我搜索谷歌,並找到許多答案檢測會話過期編程。這是代碼,我看到每個人都用它如何檢測會話過期編程
global.asax
---------------
protected void Session_Start(object src, EventArgs e)
{
if (Context.Session != null && Context.Session.IsNewSession)
{
string sCookieHeader = Request.Headers["Cookie"];
if (null != sCookieHeader && sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0)
Response.Redirect("/Session/Timeout");
}
}
我有幾個問題,關於上面的代碼 1)當會話過期則Context.Session怎麼會不爲空? 2)這條線的含義是什麼Request.Headers["Cookie"];
尋找好的討論。感謝
在Session_Start上,Session.IsNewSession將始終爲真。你想要完成什麼,因爲我認爲你正走向錯誤的道路。 –
如果你想連接到會話結束檢查這一點。 http://stackoverflow.com/questions/621744/how-to-handle-session-end-in-global-asax –