我正在编写自定义登录 - 在注销时清除cookie
public ActionResult Logout()
{
Session.Remove("Username");
Session.Clear();
if (Request.Cookies["Username"] != null)
{
HttpCookie usercookie = new HttpCookie("Username");
usercookie.Expires =DateTime.Now.AddDays(-1);
Response.Cookies.Add(usercookie);
Response.Cookies.Set(usercookie);
}
if (Request.Cookies["Password"] != null)
{
HttpCookie usercookie = new HttpCookie("Password");
usercookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(usercookie);
Response.Cookies.Set(usercookie);
}
ViewBag.Error = "Logged out !!clear cookie";
return RedirectToAction("Account","Home");
}
注销工作正常,但是在浏览器后退按钮上我得到了用户名密码,即使我在注销时清除了cookie。