子域 根域 Cookie的写入与清除
cookie的写入:
HttpCookie hc = new HttpCookie("username",uid.ToString());
hc.Expires = DateTime.Now.AddDays(1);
hc.Domain = "b.com";
HttpContext.Current.Response.Cookies.Add(hc);
此时是无法通过以下代码,直接清除的;
HttpContext.Current.Response.Cookies["username"].Expires = DateTime.Now.AddDays(-1);
最好将相应属性写完整,再进行清除:
HttpCookie cookie = HttpContext.Current.Request.Cookies["username"];
cookie.Expires = DateTime.Now.AddDays(-100);
cookie.Domain = "b.com";
HttpContext.Current.Response.Cookies.Add(cookie);