2012-06-11 62 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以防止缓存安全页面。