【问题标题】:Check for session timeout asp .net [duplicate]检查会话超时asp .net [重复]
【发布时间】:2012-10-17 13:39:01
【问题描述】:

可能重复:
How to Check whether Session is Expired or not in asp.net

页面在后面的代码中检测会话是否超时的最佳方法是什么? 我在博客 (http://mattslay.com/detecting-session-timeout-in-asp-net/) 中找到了以下代码。没问题还是有更好的方法?

if (Context.Session != null && Context.Session.IsNewSession)
{
     string cookieHeader = Page.Request.Headers["Cookie"];
     if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
          return true; // timeout occured
     else
          return false;
}

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    我建议你在你的Global.asax file 中对待这种治疗

    void Session_End(object sender, EventArgs e)
    {
       //Here you execute your treatments about end session
    }
    

    链接:http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-12
      • 2013-02-08
      • 2016-12-20
      • 2011-03-26
      • 2014-12-26
      • 1970-01-01
      • 2023-02-02
      • 2013-01-19
      相关资源
      最近更新 更多