【MVC2】发布到IIS7.5上后Session为null

MVC2代码「Session.IsNewSession」在VS中可以正常执行,发布到IIS7.5上之后Session为null导致出错。

if (Session.IsNewSession)
{
    ......
}

解决方法是在Web.config中追加如下设定:

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

参考:http://stackoverflow.com/questions/10629882/asp-net-mvc-session-is-null

原文地址:https://www.cnblogs.com/Ryukaka/p/4795283.html