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 :
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 :
But Unfortunately still I am having same issue which I have mentioned Above.
UPDATE
Do you have any solution for this ?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With