【问题标题】:Session.Abandon Not Firing or Throwing error messageSession.Abandon Not Firing 或 Throwing 错误消息
【发布时间】:2015-05-30 00:30:03
【问题描述】:

我有以下代码抛出一条错误消息,我需要在 web.config 上启用 Session,但到目前为止我没有找到任何东西,所以谁能告诉我它是如何工作的?.

我也尝试将代码放在 Page_Load 上的 Decline 中,但服务器似乎避免了 Session 的指令:

    public partial class Decline : DataPage
    {
        protected Decline() {
            Session.RemoveAll();
            Session.Clear();
            Session.Abandon();
            Response.Cookies.Remove("Accessed");
        }

       protected void Page_Load(object sender, EventArgs e)
       {  
           Response.Redirect("~/Account/Login.aspx");
       }
    }

这是完整的消息:

会话状态只能在 enableSessionState 设置为 true 时使用,无论是在配置文件中还是在 Page 指令中。还请确保 System.Web.SessionStateModule 或自定义会话状态模块包含在应用程序配置的 <configuration>\<system.web>\<httpModules> 部分中

这是运行 .net 4 框架,来自以下答案的配置不太适合我当前的项目。因为那提供了一个 .net mvc 2 解决方案。因此,如果在 .net 4 上有一个等价物,那将会很有帮助

<system.webServer>
   <modules runAllManagedModulesForAllRequests="true">
    <remove name="Session" />
    <add name="Session" type="System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </modules>
</system.webServer>

Session state can only be used when enableSessionState is set to true either in a configuration

另外,我已经为我的页面提供了以下行

<%@ Page Title="" Language="C#" CodeFile="Decline.aspx.cs" Inherits="Decline" enableSessionState="true" %> 

无论它是否存在,都没有任何区别。也在 IIS 7.5 上运行

【问题讨论】:

    标签: c# asp.net session


    【解决方案1】:

    我遇到了同样的问题,这就是我所做的 在 web.Config 中添加这个

      <system.webServer>
         <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    

    在你正在使用的页面中

    EnableSessionState="True"
    

    您可以尝试删除一个会话并检查它是否已像这样删除

    Session.Remove("test");
    if (Session["test"] == null)
    {
    //woooo it work ;
    }
    else
    {
    // what ????
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      相关资源
      最近更新 更多