Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session state can only be used when enableSessionState is set to true either in a configuration

I am working on Asp.net MVC 2 app with c# by using vs 2010.I am having below mentioned error when I run my app locally under debug mode.

Error message image is as below :

enter image description here

Error message text is as below :

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.

What I did for sort out this issue are as below :

Try 1 : web.config file has been changed like below:

<system.webServer>        <modules runAllManagedModulesForAllRequests="true">         <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 

Try 2 is as below :

enter image description here

But Unfortunately still I am having same issue which I have mentioned Above.

UPDATE

enter image description here

Do you have any solution for this ?

like image 812
Sampath Avatar asked Jan 15 '13 08:01

Sampath


People also ask

How do you enableSessionState is set to true?

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.

What is session state how it is used?

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request.

What is session state in Web config?

config or Web. config configuration file identified by the sessionState tag. When a new client begins interacting with a Web application, a session ID is issued and associated with all the subsequent requests from the same client during the time that the session is valid.


2 Answers

Did you enable the session state in the section as well?

 <system.web>       <pages enableSessionState="true" />   </system.web> 

Or did you add this to the page?

 <%@Page enableSessionState="true">  

And did you verify that the ASP.NET Session State Manager Service service is running? In your screenshot it isn't. It's set to start-up mode Manual which requires you to start it every time you want to make use of it. To start it, highlight the service and click the green play button on the toolbar. To start it automatically, edit the properties and adjust the Start-up type.

Or set the SessionState's mode property to InProc, so that the state service is not required.

 <system.web>       <sessionState mode="InProc" />  </system.web> 

Check MSDN for all the options available to you with regards to storing data in the ASP.NET session state.


Note: It's better to have your Controller fetch the value from the session and have it add the value to the Model for your page/control (or to the ViewBag), that way the View doesn't depend on the HttpSession and you can choose a different source for this item later with minimal code changes. Or even better, not use the session state at all. It can kill you performance when you're using a lot of async javascript calls.

like image 192
jessehouwing Avatar answered Sep 21 '22 07:09

jessehouwing


also if you are running SharePoint and encounter this error, don't forget to run

Enable-SPSessionStateService -DefaultProvision 

or you will continue to receive the above error message.

like image 37
Nacht Avatar answered Sep 21 '22 07:09

Nacht