小编Lok*_*oki的帖子

路由请求时,HttpContext.Current.Session为null

如果没有路由,HttpContext.Current.Session那么我知道它StateServer正在运行.当我路由我的请求时,HttpContext.Current.Sessionnull在路由页面中.我在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)

c# asp.net routing session-variables

46
推荐指数
4
解决办法
11万
查看次数

标签 统计

asp.net ×1

c# ×1

routing ×1

session-variables ×1