使用中发现用Request.Cookies.Remove()无法删除cookie
HttpCookie hc = Request.Cookies["Value"];
hc.Expires = DateTime.Now.AddDays(-1);
Response.AppendCookie(hc); //这句一定要加上,否则无法删除
顺便整理下关于Cookie的操作:
一 创建
1 单值的创建
HttpCookie hc = new HttpCookie("Value");
hc.Value = "value";
Response.AppendCookie(hc);
2 多值的创建
HttpCookie hc = new HttpCookie("Value");
hc["Value1"] = "value1";
hc["Value2"] = "value2;
Response.AppendCookie(hc);
二 读取
1 单值的读取
string value = Request.Cookies["Value"].Value;
2 多值的读取
string value1 = Request.Cookies["Value"]["Value1"].ToString();
string value2 = Request.Cookies["Value"]["Value2"].ToString();