本文转载兆维机房
本文实例讲述了ASP.NET中Cookie的用法。分享给大家供大家参考。具体分析如下:
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 = cookie.Values["webmaster"]; value2 = cookie.Values["writer"];
希望本文所述对大家的asp.net程序设计有所帮助。
http://www.e-1.cn/asp-net%E4%B8%ADcookie%E7%9A%84%E7%94%A8%E6%B3%95%E5%AE%9E%E4%BE%8B%E5%88%86%E6%9E%90.html