2014-04-02 51 views
3

我已經看到很多與此類似的問題。但是,我還沒有找到解決我的問題的答案。退出按鈕後點擊後仍然顯示頁面asp.net mvc 3

我有一個註銷按鈕,我用Session.Abandon()和Session.Clear()來清除會話。它工作正常。但是,無論何時我點擊瀏覽器上的後退按鈕,頁面仍然顯示。但是,它應該顯示登錄表單,因爲用戶已經註銷。

控制器:

[HttpPost] 
public ActionResult LogOut() 
{ 
    Session.Clear(); 
    Session.Abandon(); 
    return RedirectToAction("Index", "LogIn"); 
} 

如何解決這個問題。任何建議高度讚賞。提前致謝。

+0

您是否使用'Authorize'屬性檢查您的操作中的授權? http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx – juanreyesv

+0

@juanreyesv:不,我這樣檢查: 嘗試 { connect = connection.getConnection(); model = new Models.Entities(connect); connect.Open(); connect.Close(); } catch { return RedirectToAction(「Index」,「LogIn」); }。應該做什麼而不是做這個?謝謝。 – user3462803

回答

9

可以在global.asax

protected void Application_BeginRequest() 
{ 
    Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); 
    Response.Cache.SetNoStore(); 
} 
+0

我應該在哪裏放置這些代碼? – user3462803

+0

請重新檢查。我編輯了我的答案。 –

+0

謝謝Ashiwini!它工作! :)我只是想知道使用這種方法是否有缺點? – user3462803

0

設置NoCache的你可以將其設置爲「ServerAndNoCache」強制瀏覽器不緩存的頁面,而不是服務器,所以也有在服務器上沒有額外的負載來緩存頁面。

相關問題