当enableSessionState设置为true,无论是在配置会话状态只能用是在、设置为、只能用、状态

2023-09-02 01:32:53 作者:我的倔强你不懂

我工作的Asp.net MVC 2应用程序用C#使用VS 2010.I时遇到下面提到的错误,当我在本地运行在调试模式下我的应用程序。

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.

错误消息的图像是如下:

Error message image is as below :

错误消息的文本是如下:

Error message text is as below :

当enableSessionState设置为true会话状态只能用,   无论是在配置文件中或在Page指令。请还   确保System.Web.SessionStateModule或$自定义会话状态   模块包含在<结构> <的System.Web> <的HttpModules>   在应用程序配置部分。

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

Try 2 is as below :

可惜还是我有我刚才上面提到的同样的问题。

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

更新

你有这个什么解决办法?

Do you have any solution for this ?

推荐答案

您是否启用会话状态的部分呢?

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会话状态管理器服务服务正在运行?在您的屏幕截图事实并非如此。它设置为启动模式手动这就需要你你想利用它每次启动它。要启动它,突出服务,然后单击工具栏上的绿色播放按钮。要自动启动它,编辑属性和调整启动类型。

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的模式属性设置为是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中和你可以选择不同的来源,这个项目后来以最小的code的变化。甚至更好,not使用会话状态的所有。它可以在你使用了很多异步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.