2014-03-13 52 views
0

我是Asp.Net Mvc4的新手。我想在我註銷時清除所有會話變量。我正在使用此代碼。但它不起作用。請幫我拿到它。提前致謝。如何清除所有會話變量,當我註銷mvc4?

我的控制器代碼:

public ActionResult Logout() 
     { 
      System.Web.Security.FormsAuthentication.SignOut(); 
      Session.Clear(); 
      Session.RemoveAll(); 
      return RedirectToAction("Index", "Login"); 
     } 
+0

也許你退出後的會議已經一去不復返了。在致電SignOut之前嘗試清理會話? – Andomar

回答

0

嘗試清除Cookie太:

// 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);