2012-06-11 93 views
0

林這個代碼做註銷爲什麼註銷只能用

public ActionResult LogOff() 
    { 

     FormsAuthentication.SignOut(); 

     // Drop all the information held in the session 
     Session.Clear(); 
     Session.Abandon(); 

     // clear authentication cookie 
     HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, ""); 
     cookie1.Expires = DateTime.Now.AddYears(-1); 
     Response.Cookies.Add(cookie1); 

     // clear session cookie 
     HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", ""); 
     cookie2.Expires = DateTime.Now.AddYears(-1); 
     Response.Cookies.Add(cookie2); 
     foreach (var cookie in Request.Cookies.AllKeys) 
     { 
      Request.Cookies.Remove(cookie); 
     } 

     return RedirectToAction("Index", "Home"); 

    } 

和做工精細的地方,但本地工作,但不在服務器上,當我發表我的應用程序在服務器上,即使用戶已經註銷,如果用戶點擊瀏覽器的Back按鈕,該頁面仍會顯示。

+0

它爲什麼不起作用?怎麼了? – SLaks

+0

'Request.Cookies.Remove()'沒用。 – SLaks

+0

'Request.Cookies.Remove'不會做你認爲它做的事。 – vcsjones

回答

0

我希望你只是看到頁面的緩存版本。

如果您按CTRL + F5是否要求您再次登錄?

如果您真的想禁用此功能,請參閱MiBu給出的this answer以防止緩存安全頁面。