Author: Unknown
•19:25

[转载]

Cookie的用法也和ASP中差不多。比如我们建立一个名为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"];
value2 = cookies.Values["writer"];

This entry was posted on 19:25 and is filed under . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

0 评论: