我是Asp.Net Mvc4的新手。我想在我退出时清除所有会话变量。我正在使用此代码。但它不起作用。请帮助我得到它。提前谢谢。
我的控制器代码:
public ActionResult Logout()
{
System.Web.Security.FormsAuthentication.SignOut();
Session.Clear();
Session.RemoveAll();
return RedirectToAction("Index", "Login");
}
答案 0 :(得分: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);