2013-04-13 52 views
0

我用下面的文章就顯示到期的asp.net MVC2應用程序的警告消息的會話創建一個POC。 http://www.fairwaytech.com/2012/01/handling-session-timeout-gracefully/防止瀏覽器後退按鈕重定向到前一頁在asp.net MVC2

我已在代碼的一個變化中提到以下:在endSession方法爲以下代碼

location.href = expireSessionUrl;

window.location.replace(expireSessionUrl); 

,一旦上註銷按鈕本用戶點擊會話警告消息對話框,他將導航到LogOut視圖。但是,如果他點擊瀏覽器後退按鈕,他將導航到前一頁。

我有以下的修改過期的方法提到bleow:

[Authorize] 
public virtual ActionResult Expire() 
{ 
Session.Clear(); 
FormsService.SignOut(); 
HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); 
HttpContext.Response.Cache.SetValidUntilExpires(false); 
HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
HttpContext.Response.Cache.SetNoStore(); 
return Redirect(「/」); 
} 

能否請您指導我解決這個問題。

在此先感謝 桑托斯·庫馬爾Patro

回答

0

你需要讓你的緩存過期,試試這個:

Page.Response.Cache.SetCacheability(HttpCacheability.NoCache) 

或從docs

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60)); 
Response.Cache.SetCacheability(HttpCacheability.Public); 
Response.Cache.SetValidUntilExpires(true); 

,或者您可以使用Response.CacheControl控制頁面在用戶緩存中的存儲方式

+1

感謝您的回覆。但現在還不行。我可以點擊瀏覽器後退按鈕並導航到先前訪問過的頁面。 –

相關問題