2017-06-14 57 views
0

我已經在web.Config文件中設置了會話時間,會話超時後我希望自動刷新頁面並重定向到登錄頁面,但它沒有發生,請找到我的代碼,如下所述: - 請求幫助我,我已經嘗試了將近1周,但沒有進展。關於會話超時我的頁面沒有被刷新 - MVC 4項目

HttpContext ctx = HttpContext.Current; 

if (ctx.Session != null) 
{ 
    // check if a new session id was generated 
    if (ctx.Session.IsNewSession) 
    { 
     HttpContext ctx1 = HttpContext.Current; 
     // check sessions here 
     if (ctx.Session["UserName"] == null || !filterContext.HttpContext.Request.IsAuthenticated) 
     { 
      if (filterContext.HttpContext.Request.IsAjaxRequest()) 
      { 
       FormsAuthentication.SignOut(); 
       filterContext.Result = new RedirectResult("~/Authentication/Logon"); 
       base.OnActionExecuting(filterContext); 
      } 
     } 
    } 
} 
+0

你的'FormsAuthentication.SignOut();'執行了嗎?檢查Session [「UserName」]'是否在超時時間有值,如果不是null,那麼'Request.IsAuthenticated'永遠不會被檢查。 –

回答

0

會話僅在服務器上超時。你的頁面不會自動刷新。您需要從瀏覽器實施輪詢機制來檢查會話可用性並進行相應刷新。

+0

非常感謝,你能幫我嗎我該怎麼做? – Swathi

+0

在這裏看到正確的答案https://stackoverflow.com/questions/25433042/how-to-detect-mvc-3-session-expiration-via-javascript –

相關問題