本文實例講述了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程序設計有所幫助。