会话状态只能在配置中的 enableSessionState 设置为 true 时使用 [英] Session state can only be used when enableSessionState is set to true either in a configuration

查看:28
本文介绍了会话状态只能在配置中的 enableSessionState 设置为 true 时使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 vs 2010 使用 c# 开发 Asp.net MVC 2 应用程序.当我在调试模式下本地运行我的应用程序时,我遇到了下面提到的错误.

I am working on Asp.net MVC 2 app with c# by using vs 2010.I am having below mentioned error when I run my app locally under debug mode.

错误信息图片如下:

错误信息文本如下:

会话状态只能在 enableSessionState 设置为 true 时使用,在配置文件或 Page 指令中.还请确保 System.Web.SessionStateModule 或自定义会话状态模块包含在 应用程序配置中的部分.

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration><system.web><httpModules> section in the application configuration.

我为解决这个问题所做的如下:

What I did for sort out this issue are as below :

尝试 1:web.config 文件已更改如下:

Try 1 : web.config file has been changed like below:

<system.webServer>
       <modules runAllManagedModulesForAllRequests="true">
        <remove name="Session" />
        <add name="Session" type="System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
</system.webServer

尝试 2 如下:

但不幸的是,我仍然遇到了上面提到的相同问题.

But Unfortunately still I am having same issue which I have mentioned Above.

更新

你有什么解决办法吗?

推荐答案

您是否也启用了该部分中的会话状态?

Did you enable the session state in the section as well?

 <system.web>
      <pages enableSessionState="true" /> 
 </system.web>

或者您是否将其添加到页面中?

Or did you add this to the page?

 <%@Page enableSessionState="true"> 

您是否验证了 ASP.NET Session State Manager Service 服务正在运行?在您的屏幕截图中,它不是.它设置为启动模式Manual,这要求您每次要使用它时都启动它.要启动它,请突出显示该服务并单击工具栏上的绿色播放按钮.要自动启动,请编辑属性并调整启动类型.

And did you verify that the ASP.NET Session State Manager Service service is running? In your screenshot it isn't. It's set to start-up mode Manual which requires you to start it every time you want to make use of it. To start it, highlight the service and click the green play button on the toolbar. To start it automatically, edit the properties and adjust the Start-up type.

或者将SessionState的mode属性设置为InProc,这样状态服务就不需要了.

Or set the SessionState's mode property to InProc, so that the state service is not required.

 <system.web>
      <sessionState mode="InProc" />
 </system.web>

检查 MSDN 中的所有可用选项关于在 ASP.NET 会话状态中存储数据.

注意:最好让您的控制器从会话中获取值并将值添加到您的页面/控件(或添加到 ViewBag)的模型中,这样视图就不会依赖于 HttpSession 和您可以稍后为该项目选择不同的来源,只需进行最少的代码更改.或者甚至更好,根本不使用会话状态.当您使用大量异步 javascript 调用时,它会降低您的性能.

Note: It's better to have your Controller fetch the value from the session and have it add the value to the Model for your page/control (or to the ViewBag), that way the View doesn't depend on the HttpSession and you can choose a different source for this item later with minimal code changes. Or even better, not use the session state at all. It can kill you performance when you're using a lot of async javascript calls.

这篇关于会话状态只能在配置中的 enableSessionState 设置为 true 时使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆