Session state can only be used when enableSessionState is set to true

29,208

I spent lot of time debugging this issue. Our website is working fine till yesterday and suddenly stopped working with error.

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.

When checked ASP.net State Service is missing from the service list.

reinstalling it as below helped to resolve the issue.

C:\Windows\Microsoft.Net\Framework64\v4.0.30319\aspnet_regiis -i

Share:
29,208
user786423
Author by

user786423

Updated on August 27, 2020

Comments

  • user786423
    user786423 over 3 years

    I am NOT using MVC, URL rewriting, custom HTTP modules, etc. On a basic call to the Session property off of either a web page inheriting System.Web.UI.Page or via System.Web.HttpContext.Current.Session, I get the following error:

    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.

    After doing some research, I have implemented Web.config as follows, but the error still occurs. I am debugging the web app out of Visual Studio 2010 using the built-in web server.

    <configuration>
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
            <sessionState mode="InProc" timeout="60" cookieless="false" />
            <pages enableSessionState="true" />
            <httpModules>
                <remove name="Session" />
                <add name="Session" type="System.Web.SessionState.SessionStateModule" />
            </httpModules>
        </system.web>
    </configuration>