微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.net – 只有在配置中enableSessionState设置为true时才可以使用会话状态

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

错误消息图像如下:

错误消息文本如下:

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.

为了整理这个问题我做了如下:

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

<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如下:

但不幸的是,我仍然有同样的问题,我上面提到过。

UPDATE

你有什么解决办法吗?

解决方法

您是否也在该部分启用会话状态?
<system.web>
      <pages enableSessionState="true" /> 
 </system.web>

还是添加页面

<%@Page enableSessionState="true">

您是否验证ASP.NET会话状态管理器服务是否正在运行?在你的屏幕截图中,它不是。它设置为启动模式手动,需要您每次要使用它时启动它。要启动它,请突出显示该服务,然后单击工具栏上的绿色播放按钮。要自动启动,请编辑属性并调整启动类型。

或者将SessionState的mode属性设置为InProc,以便不需要状态服务。

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

检查MSDN for all the options available to you with regards to storing data in the ASP.NET session state

注意:最好让Controller从会话中获取值,并将值添加到您的页面/控件(或ViewBag)的Model中,这样View不依赖于HttpSession,您可以选择这个项目的不同来源,稍后以最小的代码更改。或者甚至更好,not use the session state at all.当你使用大量的异步javascript调用时,它可以杀死你的性能

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐