tags:

views:

2205

answers:

4

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

+8  A: 

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 ;-)

Mouffette
lucky you! i'm still trying to fix this one on a bog standard mvc app deployed to an iis 6 virtual directory. my web config and iis both have session state enabled and my modules section already contained the snippet that fixed this for you. i'm stumped.
grenade
+2  A: 

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.

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

Bryan DeYoung
A: 

Add the following entry to system.webServer/handlers

<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc"/>

Change path="*.mvc" to whatever extension/path you are using.

Using runAllManagedModulesForAllRequests="true" is not a very good solution because all modules will run for every request, including static files, which can be bad for performance.

Max Toro
that makes sense. thanks.
Mouffette
A: 

If you happen to be using SQLServer as the sessionState mode such as

<sessionState mode="SQLServer" sqlConnectionString="data source=server;integrated security=true" cookieless="false" />

make sure the connection string is correct and you have permission to the database. I realize this question was for InProc mode, but I hit the same error when I forgot to grant privs to the account my app was running as and this question was the top hit in my Google search.

Chad