刪除Cookie可能重複:
Delete cookie on clicking sign out如何從淨
我想,當用戶註銷刪除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);
}
}
但它不工作。你有什麼建議嗎?
我相信你不應該清除'價值'。 AFAIK,這就是cookie的識別方式。 –
請注意,刪除cookie只是輔助清理。重要的部分是使服務器端cookie的值無效。 – CodesInChaos