【发布时间】:2012-08-20 10:30:14
【问题描述】:
我想在用户注销时删除 cookie。
这是我的代码:
if (HttpContext.Current.Request.Cookies["currentUser"] != null)
{
DeleteCookie(HttpContext.Current.Request.Cookies["currentUser"]);
}
public void DeleteCookie(HttpCookie httpCookie)
{
try
{
httpCookie.Value = null;
httpCookie.Expires = DateTime.Now.AddMinutes(-20);
HttpContext.Current.Request.Cookies.Add(httpCookie);
}
catch (Exception ex)
{
throw (ex);
}
}
但它不起作用。你有什么建议吗?
【问题讨论】:
-
我认为你不应该清除
Value。 AFAIK,这就是识别 cookie 的方式。 -
请注意,删除 cookie 只是二次清理。重要的部分是使服务器端 cookie 的值无效。