(1)设置
HttpCookie user =
new
HttpCookie(
"User"
);
user[
"ID"
] = Session[
"ID"
].ToString();
user[
"UID"
] = Session[
"UID"
].ToString();
HttpContext.Current.Response.Cookies.Add(user);
(2)取出
HttpContext.Current.Request.Cookies[
"User"
].Values[
"ID"
]
HttpContext.Current.Request.Cookies[
"User"
].Values[
"UID"
]
(3)用法
比如建立一个名为aspcn,值为灌水小鱼的cookie
HttpCookie cookie = new HttpCookie["aspcn"];
cookie.Value = "灌水小鱼";
Response.AppendCookie(cookie);
取出Cookie值也很简单
HttpCookie cookie = Request.Cookies["aspcn"];
cookieValue = cookie.Value;
在一个Cookie中储存多个信息,那也没有问题。比如在名为aspcn的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"];
HttpCookie cookie = new HttpCookie["aspcn"];
cookie.Value = "灌水小鱼";
Response.AppendCookie(cookie);
取出Cookie值也很简单
HttpCookie cookie = Request.Cookies["aspcn"];
cookieValue = cookie.Value;
在一个Cookie中储存多个信息,那也没有问题。比如在名为aspcn的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"];