Error using session in IIS 7(在 IIS 7 中使用会话时出错)
问题描述
将我的网站部署到 IIS 后,尝试访问会话时收到以下错误消息:
After deployment of my website to IIS, I'm getting the following error message when trying to access a session:
会话状态只能在以下情况下使用enableSessionState 设置为 true,在配置文件或页面指令.也请制作确定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 \ section in the application configuration.
我在 Page_Load
或 PreRender
事件中访问它(我尝试了两个版本).使用 Visual Studio Dev Server,它可以毫无问题地工作.我尝试了 InProc
和 SessionState
存储、1 个和多个工作进程.我明确地将 enableSessionState = "true"
添加到我的网页.这是 web.config
的一部分:
I access it in Page_Load
or PreRender
events (I tried both versions). With Visual Studio Dev Server it works without a problem. I tried both InProc
an SessionState
storage, 1 and multiple worker processes. I added a enableSessionState = "true"
to my webpage explicitly.
Here is part of web.config
:
<system.web>
<globalization culture="ru-RU" uiCulture="ru-RU" />
<compilation debug="true" defaultLanguage="c#">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<pages enableEventValidation="false" enableSessionState="true">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="SearchUrlRewriter" type="Synonymizer.SearchUrlRewriter, Synonymizer, Version=1.0.0.0, Culture=neutral" />
<add name="Session" type="System.Web.SessionStateModule" />
</httpModules>
<sessionState cookieless="UseCookies" cookieName="My_SessionId" mode="InProc" stateNetworkTimeout="5" />
<customErrors mode="Off" />
</system.web>
我还需要做什么才能让它发挥作用?
What else do I need to do to make it work?
我尝试监控 IIS 是否使用 Process Monitor<访问 aspnet_client
文件夹/a> 并且没有任何访问权限.
I tried to monitor if IIS accesses the aspnet_client
folder with Process Monitor and didn't get any access.
推荐答案
解决方案正好很好奇.虽然 IIS7 jn WIndows 2008R2 在错误描述中说要将 SessionStateModule 添加到 system.web 部分,但它应该添加到 system.webServer 部分.
The solution happened to be very curious. Though IIS7 jn WIndows 2008R2 in error description says to add SessionStateModule to system.web section, it should be added to system.webServer section.
<system.webServer>
<modules>
<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>
这篇关于在 IIS 7 中使用会话时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 IIS 7 中使用会话时出错
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30