user786423
user786423

Reputation: 125

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

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>

Upvotes: 6

Views: 29915

Answers (3)

HydTechie
HydTechie

Reputation: 606

This issue is reproduced in my known scenarios....

If a frameset or a two parallel requests are emerging from browsers, if these both pages have same custombase page, accessing session resulted in this exception due to multiple worker threads...

UPDATE: To all sufferers of this problem, I have my findings here! 1. I could reproduce this issue in IE browser(IE10) and FIREFOX(22), though I have great settings of all enabled..etc.etc... in my local code, WHEN IE settings in Connection Tab --> LAN settings have "Use PROXY Server for Localhost..." checkbox shown as CHECKED - without a VALID PROXY server setting...

When I uncheck this In IE, the same code with DEFAULT Session settings, runs like HORSE!!

Hope that give some light,

Thanks

Upvotes: 0

jtirumani
jtirumani

Reputation: 21

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

Upvotes: 1

user1624372
user1624372

Reputation:

Your problem is straight forward. If you shift your code from a place that is executed after Session_Start global event, then you will see this problem go quite comfortably. As an example write your code in Page_Init event or override OnInit and do whatever you want to do with your Session there.

Hope this will work for you.

Upvotes: 3

Related Questions