在 IIS 7 中使用会话时出错 [英] Error using session in IIS 7

查看:26
本文介绍了在 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_LoadPreRender 事件中访问它(我尝试了两个版本).使用 Visual Studio Dev Server,它可以毫无问题地工作.我尝试了 InProcSessionState 存储、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 中使用会话时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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