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

I DO NOT use MVC, URL rewriting, HTTP custom modules, etc. A basic call to the Session property disables either the web page that inherits from System.Web.UI.Page, or through System.Web.HttpContext.Current. Session, I get the following error:

Session state can only be used when enableSessionState is set to true, either in the configuration file or in the Page directive. Also make sure that the System.Web.SessionStateModule or user session state module is included in the <configuration>\<system.web>\<httpModules> in the application configuration.

After some research, I implemented Web.config as follows, but the error still occurs. I am debugging a web application from Visual Studio 2010 using the embedded 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> 
+6
source share
3 answers

Your problem is straightforward. If you move your code from a place that executes after the global Session_Start event, you will see that this problem will be quite comfortable. As an example, write your code in the Page_Init event or override OnInit and do what you want to do with your session there.

Hope this works for you.

+3
source

I spent a lot of time debugging this problem. Our site works until yesterday and suddenly stops working with an error.

Session state can only be used when enableSessionState is set to true, either in the configuration file or in the Page directive. Also, make sure that the System.Web.SessionStateModule or the session state custom module is included in the \\ section in the application configuration.

When checking the status service, ASP.net is not in the list of services.

reinstalling it as shown below helped solve the problem.

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

+1
source

This problem reproduces itself in my famous scripts ....

If a set of frames or two parallel requests appears from browsers, if both of these pages have the same user base page, access to the session led to this exception due to several workflows ...

UPDATE: For everyone suffering from this problem, I have my conclusions here! 1. I could reproduce this problem in IE browser (IE10) and FIREFOX (22), although I have excellent settings for all allowed..etc.etc ... in my local code, WHEN IE Settings in Connection tab → LAN in the settings, the checkbox "Use PROXY Server for localhost" is checked ... CHECKED - without configuring the VALID PROXY server ...

If you clear this check box in IE, then the same code with the settings of the DEFAULT session is executed as HORSE !!

Hope we give some light

thanks

0
source

All Articles