Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using session in IIS 7

After deployment of my website to IIS, I'm getting the following error message when trying to access a session:

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.

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?

I tried to monitor if IIS accesses the aspnet_client folder with Process Monitor and didn't get any access.

like image 910
flashnik Avatar asked May 03 '10 10:05

flashnik


1 Answers

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>
like image 122
flashnik Avatar answered Oct 21 '22 22:10

flashnik