加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 00:41:28 所属栏目:asp.Net 来源:网络整理
导读:我正在使用vs 2010.在Asp.net MVC 2应用程序与c#。当我在调试模式下本地运行我的应用程序时,我有下面提到的错误。 错误消息图像如下: 错误消息文本如下: Session state can only be used when enableSessionState is set to true, either in a configurat
我正在使用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调用时,它可以杀死你的性能。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读