asp.net Cookie用法举例

发布时间:2020-10-21编辑:脚本学堂
asp.net Cookie用法举例
复制代码 代码如下:
设置cookie:
HttpCookie cookie = new HttpCookie["aspcn"];
cookie.Value = "飞刀";
Response.AppendCookie(cookie);

读取cookie:
HttpCookie cookie = Request.Cookies["aspcn"];
cookieValue = cookie.Value;

Cookie储存多个信息:
HttpCookie cookie = new HttpCookie("aspcn");
cookie.Values.Add("webmaster","飞刀");
cookie.Values.Add("writer","beige");
cookie.Values.Add("LinkColor","blue");
Response.AppendCookie(cookie);

读取多个信息:
HttpCookie cookie = Request.Cookies["aspcn"];
value1 = cookies.Values["webmaster"];
value2 = cookies.Values["writer"];