Asp.net 的cookie问题
写代码的发现的小问题
如果写入cookie的时候指定了domin域名
那么删除的时候必须也指定domin域名才行,即使你先读取了这个已经存在的cookie,但是还是要指定domin才能删除
/// <summary>
/// 删除指定Cookie
/// </summary>
/// <param name="cookieName"></param>
public static void RemoveCookie(string cookieName)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];// new HttpCookie(cookieName);
if (cookie != null)
{
//httpContext.Current.Request.Cookies.Remove(cookieName);
cookie.Expires = DateTime.Now.AddDays(-1);
cookie.Domain = ".xxxx.com";
HttpContext.Current.Response.SetCookie(cookie);
}
}