Example analysis of usage of Cookie in ASP. NET
- 2021-07-01 07:12:46
- OfStack
This article illustrates the use of Cookie in ASP. NET. Share it for your reference. The specific analysis is as follows:
The usage of Cookie is similar to that of ASP. For example, we create an cookie named aspcn with a value of flying knife
HttpCookie cookie = new HttpCookie["aspcn"];
cookie.Value = " Throwing knife ";
Response.AppendCookie(cookie);
It is also very simple for us to take out the Cookie value
HttpCookie cookie = Request.Cookies["aspcn"];
cookieValue = cookie.Value;
Sometimes we want to store multiple messages in one Cookie, which is no problem. For example, we add multiple messages under cookie named aspcn
HttpCookie cookie = new HttpCookie("aspcn");
cookie.Values.Add("webmaster"," Throwing knife ");
cookie.Values.Add("writer","beige");
cookie.Values.Add("LinkColor","blue");
Response.AppendCookie(cookie);
It is also simple to take out information
HttpCookie cookie = Request.Cookies["aspcn"];
value1 = cookie.Values["webmaster"];
value2 = cookie.Values["writer"];
I hope this article is helpful to everyone's asp. net programming.