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 ?
This question is related to
.net
visual-studio-2010
session
asp.net-mvc-2
Session State may be broken if you have the following in Web.Config:
<httpModules>
<clear/>
</httpModules>
If this is the case, you may want to comment out such section, and you won't need any other changes to fix this issue.
Following answer from below given path worked fine.
I found a solution that worked perfectly! Add the following to web.config:
<system.webServer>
<modules>
<!-- UrlRewriter code here -->
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
</modules>
</system.webServer>
Hope this helps someone else!
I realise there is an accepted answer, but this may help people. I found I had a similar problem with a ASP.NET site using NET 3.5 framework when running it in Visual Studio 2012 using IIS Express 8. I'd tried all of the above solutions and none worked - in the end running the solution in the in-built VS 2012 webserver worked. Not sure why, but I suspect it was a link between 3.5 framework and IIS 8.
I have got this error only when debugging the ASP .Net Application.
I also had Session["mysession"]
kind of variables added into my Watch of Visual Studio.
the issue was solved Once, I have removed the Session Variables from watch.
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.
I want to let everyone know that sometimes this error just is a result of some weird memory error. Restart your pc and go back into visual studio and it will be gone!! Bizarre! Try that before you start playing around with your web config file etc like I did!!!! ;-)
For SharePoint Can find the web config file in C:\inetpub\wwwroot\wss\VirtualDirectories\Sitecollection port number - and Make changes
<system.web>
<pages enableSessionState="true" />
</system.web>
and using SharePoint Management Shell Run below Command
Enable-SPSessionStateService -DefaultProvision
Solves the above problem, It solved mine!
HydTechie
In my case problem went away simply by using HttpContext.Current.Session
instead of Session
This error was raised for me because of an unhandled exception thrown in the Public Sub New()
(Visual Basic) constructor function of the Web Page in the code behind.
If you implement the constructor function wrap the code in a Try/Catch statement and see if it solves the problem.
Actually jessehouwing
gave the solution for normal scenario.
But in my case I have enabled 2 types of session in my web.config file
It's like below.
First one :
<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>
Second one :
<sessionState mode="Custom" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PawLoyalty" applicationName="PawLoyalty"/>
</providers>
</sessionState>
So in my case I have to comment Second one.B'cos that thing for the production.When I commented out second one my problem vanished.
Source: Stackoverflow.com