← All articles
development

ASP.NET MVC Managed Requests

Fixing SessionStateTempDataProvider requires SessionState to be enabled in ASP.NET MVC: add runAllManagedModulesForAllRequests to your config.

Donn Felker

Donn Felker

2009.01.14 · 1 min read · updated July 5, 2013

Ran into an interesting problem today and the links I found on the net did not help me resolve the issue.

The Error

The SessionStateTempDataProvider requires SessionState to be enabled.

How To Fix

To see what the problem was I ran a quick “File – New MVC App” and fired it up. It worked. I knew something must be awry with the config file. After poking around a team member of mine noticed the error.

Current Config (which throws the exception)

<modules >
<remove name="ScriptModule" />
<remove name="UrlRoutingModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>

There was an attribute missing from the module element. After adding the attribute it looks like this:

<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule" />
<remove name="UrlRoutingModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>

What is the runAllManagedModulesForAllRequests attribute and what does it do?

ScottGu puts it very well:

Note the “runAllManagedModulesForAllRequests” attribute that is set to true on the section within <system.webServer>.  This will ensure that the UrlRewriter.Net module from Intelligencia, which was written before IIS7 shipped, will be called and have a chance to re-write all URL requests to the server (including for folders).  What is really cool about the above web.config file is that:

1) It will work on any IIS 7.0 machine.  You don’t need an administrator to enable anything on the remote host.  It will also work in medium trust shared hosting scenarios.

2) Because I’ve configured the UrlRewriter in both the and IIS7 section, I can use the same URL Rewriting rules for both the built-in VS web-server (aka Cassini) as well as on IIS7.  Both fully support extension-less URLRewriting.  This makes testing and development really easy.

After applying the attribute to my module element everything worked as expected.

Donn Felker

Written by Donn Felker

I've spent 25+ years shipping software, writing books, and running my own companies. I write about thinking clearly, working for yourself, and doing real work while AI rewrites the rules. New essays land here every week.

Get the newsletter

Keep reading