不,您不能因爲超時編碼在身份驗證Cookie上,並且存在於瀏覽器(不在服務器端)。
您可以作出這樣的習俗,也保持數據庫的用戶等待時間 - 但它不是那麼容易,替代你可以使用Application_AuthenticateRequest
在Global.asax的請求之前,有權檢查,如果用戶沒有通過驗證任何更多。
如果用戶未通過身份驗證,如何刪除會話數據的一個示例。關於全球asax。
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
// get the authCookie
HttpCookie authCookie = Context.Request.Cookies[cookieName];
// if is null then the use is not Authendicated
if (null == authCookie && System.Web.HttpContext.Current.Session != null)
{
// now check if you have Session variables that you wish to remove.
if(System.Web.HttpContext.Current.Session["flag"] == "1")
{
// remove your session data
}
}
}
您也許還要檢查與
if(HttpContext.Current.User == null || HttpContext.Current.User.Identity == null || !HttpContext.Current.User.Identity.IsAuthenticated)
{
// now check if you have Session variables that you wish to remove.
if(Session["flag"] == "1")
{
// remove your session data
}
}
我的問題是,當我的窗體身份驗證超時,會話變量仍然存在。如何處理這種情況,請告知,謝謝Aristos! – jomsk1e 2013-05-14 05:39:27
@JRC我會在答案中加入一個例子。 – Aristos 2013-05-14 05:40:50
你的第一個答案後,我試圖刪除global.asax中的Application_AuthenticateRequest中的會話,但我得到了一個HttpException,表示會話狀態在此上下文中不可訪問。 :( – jomsk1e 2013-05-14 05:56:57