【问题标题】:can't get System.Web.SessionState with asp.net 4 webforms routing无法使用 asp.net 4 webforms 路由获取 System.Web.SessionState
【发布时间】:2010-09-14 19:46:08
【问题描述】:

我在这里看到了几个问题,例如State Service when using system.web.routing in WebForms,但找不到合适的解决方案。

我在 iis7 上使用带有 webforms 的 asp.net 路由。我已将以下内容添加到 webconfig 文件中,以使其在第一宫工作

       <system.webServer><modules>
        <remove name="UrlRoutingModule-4.0" />
        <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />   
 </modules>
     </system.webServer>

问题是当我使用路由页面时,会话状态不可用,我得到了

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>\<system.web>\<httpModules> section in the application configuration.

我启用了 sesison 状态,如果我使用 aspx 扩展名而不是路由 url 调用页面本身,一切正常。

有人知道如何通过路由获取会话状态吗?

【问题讨论】:

    标签: asp.net routing .net-4.0 session-state


    【解决方案1】:

    知道了!见http://www.heartysoft.com/post/2010/07/26/aspnet-routing-iis7-remember-modules.aspx

    <system.webServer> 
    <modules > 
    <remove name="UrlRoutingModule-4.0" /> 
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> 
    <remove name="Session"/> 
    <add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition=""/> 
    

    【讨论】:

    • 如果您使用的是.NET4.0和VS2010,您根本不需要在web.config中指定UrlRouting和SessionState模块,这些都是自动为您完成的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2011-08-08
    • 2016-01-06
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    相关资源
    最近更新 更多