HttpContext.Current.Session is null when routing requests HttpContext.Current.Session is null when routing requests asp.net asp.net

HttpContext.Current.Session is null when routing requests


Got it. Quite stupid, actually. It worked after I removed & added the SessionStateModule like so:

<configuration>  ...  <system.webServer>    ...    <modules>      <remove name="Session" />      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>      ...    </modules>  </system.webServer></configuration>

Simply adding it won't work since "Session" should have already been defined in the machine.config.

Now, I wonder if that is the usual thing to do. It surely doesn't seem so since it seems so crude...


Just add attribute runAllManagedModulesForAllRequests="true" to system.webServer\modules in web.config.

This attribute is enabled by default in MVC and Dynamic Data projects.


runAllManagedModulesForAllRequests=true is actually a real bad solution. This increased the load time of my application by 200%. The better solution is to manually remove and add the session object and to avoid the run all managed modules attribute all together.