今天发现在本机上可以删除Cookie,只是把Cookie时间改为过期cookie.Expires = DateTime.Now.AddDays(-7);即可,但是部署到服务器之后一直无法删除,后来发现问题
public static void Remove(string cookieName, string domain) { //HttpCookie cookie = new HttpCookie(cookieName); //HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookieName]; HttpCookie cookie = new HttpCookie(cookieName); cookie.Expires = DateTime.Now.AddDays(-7); cookie.Domain = domain; //HttpContext.Current.Response.Cookies.Add(cookie); HttpContext.Current.Response.Cookies.Set(cookie); //System.Web.HttpContext.Current.Request.Cookies.Set(cookie); }本机上使用这个注释掉得代码是可以的,但是服务器上的不行
HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookieName];
改为以下代码就可以了HttpCookie cookie = new HttpCookie(cookieName);