Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The SessionStateTempDataProvider requires SessionState to be enabled

Tags:

asp.net-mvc

My hybrid (web forms/MVC) project is working fine in my local development environment BUT when I deploy (xcopy) to my Test environment I get the error that SessionState is needed (full error shown below).

What's strange about this error message is that session state is set as InProc in my web.config and IIS7 configuration shows it as as well.

I'm running a classic web forms site and only have one small section that I'm moving over to MVC 1.0. And now my regular web forms default.aspx page isn't able to come up!

  • I don't use the TempData provider at all in MVC so I'm guessing the framework does for some reason but heck, my SesionState is Enabled...
  • My test environment is running on IIS 7 in Integrated mode with my webconfig with sessionstate as InProc and works fine.

More Info: For fun I created a stub project that was MVC only and deployed it to the Test environment and it worked fine! The web.config's are essentially the same and one works and the other doesn't.

Any help is appreciated.


Error Message

Server Error in '/' Application.

The SessionStateTempDataProvider requires SessionState to be enabled. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The SessionStateTempDataProvider requires SessionState to be enabled. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The SessionStateTempDataProvider requires SessionState to be enabled.] System.Web.Mvc.SessionStateTempDataProvider.LoadTempData(ControllerContext controllerContext) +247928 System.Web.Mvc.TempDataDictionary.Load(ControllerContext controllerContext, ITempDataProvider tempDataProvider) +30 System.Web.Mvc.Controller.ExecuteCore() +71 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +209 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

like image 558
Mouffette Avatar asked Apr 06 '09 05:04

Mouffette


People also ask

What will happen if we are using TempData in controller and we have disabled session?

TempData in MVC uses session state internally to store the data. So when we disable the session state for the controller, it will throw the exception as below.

Can we use session state in MVC?

By default, Asp.Net MVC support session state. Session is used to store data values across requests. Whether you store some data values with in the session or not Asp.Net MVC must manage the session state for all the controllers in your application that is time consuming.

What is Session state in MVC?

Session state is an ASP.NET Core scenario for storage of user data while the user browses a web app. Session state uses a store maintained by the app to persist data across requests from a client.


2 Answers

Google Solved: I added this attribute to the modules node in the web.config and EVERYTHING magically started working:

<modules runAllManagedModulesForAllRequests="true">

It looks like I'm not alone:

http://forums.asp.net/p/1293974/2509190.aspx

http://www.flyvergrillen.dk/2009/03/26/being-trapped-in-iis/

I think my pure MVC project (that worked in Test environment) was too simple and may not have forced the MVC framework to require TempData and SessionState, so that's how I'll explain it away ;-)

like image 97
Mouffette Avatar answered Nov 15 '22 08:11

Mouffette


I had the same problem and was of course getting the same error. Even though, I did not need the Session state for my MVC application, I was just interested in getting the application up and running so was willing to enable the session state...why not!!

Even after adding the session state setting to my web.config file,

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

I continued to get the same error message....very confusing!.

I discovered the following explanation which was the definitive resolution to the issue. When running the app pool in integrated mode, you have to ensure that IIS has the session state module mapping defined.

like image 21
2 revs, 2 users 87% Avatar answered Nov 15 '22 09:11

2 revs, 2 users 87%