如果没有路由,HttpContext.Current.Session
那么我知道它StateServer
正在运行.当我路由我的请求时,HttpContext.Current.Session
是null
在路由页面中.我在IIS 7.0上使用.NET 3.5 sp1,没有MVC预览.似乎AcquireRequestState
在使用路由时从不触发,因此会话变量未实例化/填充.
当我尝试访问Session变量时,我收到此错误:
base {System.Runtime.InteropServices.ExternalException} = {"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>.
在调试时,我也得到了HttpContext.Current.Session
在该上下文中无法访问的错误.
-
我web.config
看起来像这样:
<configuration>
...
<system.web>
<pages enableSessionState="true">
<controls>
...
</controls>
</pages>
...
</system.web>
<sessionState cookieless="AutoDetect" mode="StateServer" timeout="22" /> …
Run Code Online (Sandbox Code Playgroud)