以下是我刚刚完善的删除cookie的方法
/// <summary> /// 删除Cookies /// </summary> /// <param name="CoName">Cookie的名称</param> /// <param name="domain">Cookie的domain</param> /// <returns>布尔类型</returns> public static void DeleteCookie(string CoName, string domain) { if (HttpContext.Current.Request.Browser.Cookies) { if (HttpContext.Current.Request.Cookies[CoName] != null) { HttpCookie cookie = new HttpCookie(CoName); cookie.Expires = DateTime.Now.AddYears(-5); if (!string.IsNullOrEmpty(domain)) { cookie.Domain = domain; } HttpContext.Current.Response.Cookies.Add(cookie); } } //else //{ // HttpContext.Current.Session[CoName] = ""; //} }
DeleteCookie("total",""); 删除不掉total
DeleteCookie("count",""); 可以删除掉count
DeleteCookie("total","mydomain.com“); 可以删除掉total
DeleteCookie("count","mydomain.com“); 删除不掉count
DeleteCookie("total","mydomain.com“);
DeleteCookie("count","");