时间:2021-07-01 10:21:17 帮助过:10人阅读
本文实例讲述了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程序设计有所帮助。