In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the writing methods of cookie code in asp.net". In daily operation, I believe that many people have doubts about the writing method of cookie code in asp.net. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the writing methods of cookie code in asp.net?" Next, please follow the editor to study!
Cookie is a piece of text message, and storing Cookie on the client is one of the ways in which ASP.NET 's session state associates a request with a session. Cookie can also be used directly to hold data between requests, but the data is then stored on the client and sent to the server with each request. Browsers have a limit on the size of Cookie, so no more than 4096 bytes are guaranteed to be accepted.
Write Cookie
The copy code is as follows:
/ / method 1:
Response.Cookies ["username"] .value = "mike"
Response.Cookies ["username"] .Expires=DateTime.MaxValue
/ / method 2:
HttpCookie acookie = new HttpCookie ("last")
Acookie.Value= "a"
Acookie..Expires=DateTime.MaxValue
Response.Cookies.Add (acookie)
/ / method 1:
Response.Cookies ["userinfo1"] ["name"] .value = "mike"
Response.Cookies ["userinfo1"] ["last"] .value = "a"
Response.Cookies ["userinfo1"] .Expires=DateTime.MaxValue
/ / method 2:
HttpCookie cookie = new HttpCookie ("userinfo1")
Cookie.Values ["name"] = "mike"
Cookie.Values ["last"] = "a"
Cookie.Expires=DateTime.MaxValue
/ / cookie.Expires = System.DateTime.Now.AddDays (1); / / set the expiration time to 1 day
Response.Cookies.Add (cookie)
Read Cookie
Internet Explorer saves the Cookie of the site in a file with a file name of @ .txt, where is your account name.
Note: before getting the value of Cookie, you should make sure that the Cookie does exist. Otherwise, you will get an exception
The copy code is as follows:
If (Request.Cookies ["userName"]! = null)
{
String str = Request.Cookies ("userName") .Value
}
/ / Reading of multi-valued Cookie
If (Request.Cookies ["userInfo1"]! = null)
{
String name=Request.Cookies ["userInfo1"] ["name"]
String last=Request.Cookies ["userInfo1"] ["last"]
}
/ / read the Cookie collection
For (int I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.