Cookies

1.创建
HttpCookies Cookie=new HttpCookies("CookieName");
2.添加内容
Cookie.Values.Add("UserName","ABC");

Cookie["UserName"]="ABC";
3. Modify the content
Cookie.Values["UserName"]="CBA";
4. Read the content
var UserName=Cookie.Values["UserName"];
5. Set the expiration time (Deleting a cookie means that the expiration time is set earlier than the current time, and the cookie will be automatically deleted the next time the webpage is opened)
(The time to delete a cookie is the next time a new webpage is opened, that is, if a new webpage is not opened, the cookie will not be opened. Will be deleted, still)
(the data in it can be read)
Cookie.Expires=DateTime.Now;
6. Pass the modified information to the client (all change operations must do this, otherwise the changes will not be saved to the client End Cookie)
Response.AppendCookies(Cookie): Append Http cookie to the Cookies collection, the cookie with the same key can be added repeatedly, always added instead of updated, it has almost the same function as HttpResponse.Cookies.Add, the biggest difference is The events and exceptions thrown before and after adding are not the same.
HttpResponse.Cookies.Add: Add the specified cookie to the Cookies collection. Cookies with the same key can be added repeatedly. Always add instead of updating.
HttpResponse.SetCookie: Update the first cookie with the same key in the Cookies collection. If the same key is not found key cookie, add a cookie to the Cookies collection.
7. Get Client Cookies
Request.Cookies["CookieName"];
8. The value of Expires cannot be obtained from the client's Cookies, so to judge the time, a new Values[] is needed to store

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324856481&siteId=291194637