Being trapped in IIS

Mikkel has just spend a lot of time trying to get ASP.net MVC to work on a server. During this quest he bumped in to a lot of headache inducing problems the worst of which I will describe here and provide some sort of solution.

The error our dear setup threw at us was:

System.InvalidOperationException:
    The SessionStateTempDataProvider requires SessionState to be enabled.

The only results on google were suggesting to add a line in web.config to tell ISS and ASP.net that sessionState mode should be enabled. Trying this and still getting the same error we found this:

On the Session State tab in IIS, is it also set to enabled?

If you are reading this, you are probably having the some understanding of how the IIS7 management gui works and how it looks. It has no notion of Tabs, and no configuration icons relating to session at all.

Poking around at every concievable way to add SessionState we found that it was possible to add a module named:

System.Web.SessionState.SessionStateModule

Adding that module created the following in web.config:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
       <add name="SessionStateModule"
            type="System.Web.SessionState.SessionStateModule" />

Rembering to add this:

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

made the server happy.

Hopefully someone in the same situation will find this helpful.

ps: If you are getting weird errors (0×80070021) about system.webServer handlers not being recognized you’ll need to enable them using the cheatcodes:

%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers
%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/modules

5 Responses to “Being trapped in IIS”

  1. Stuart Clark says:

    Hey thanks a lot I’ve been trying to solve this problem for days now :)

  2. AK says:

    Ah, thanks folks – exactly what I needed.

  3. Just a little note: If you copy/paste from this article, remember that WordPress is turning the quotes in attributes into something it thinks is more pretty. Replace them with normal quotes, or you’ll end up getting an error 500.

  4. keith says:

    THANK YOU! That has been driving me nuts.

  5. Bryan DeYoung says:

    Mikkel,

    Thank your for the great information. I needed to add the SessionStateModule to my instance of IIS 7.0. I had the same problem that you had until this was added.

    Apparently, you cannot turn off the session state with the first release of MVC. The MVC team noted that this is fixed in the MVC 2.0 release.

    Thanks again for saving me lots of time!!

Leave a Reply