Cookie (httpcookie instance) provides a web applicationProgramTo store user-specific information. For example, when a user accesses your site, you can use cookies to store user preferences or other information. When the user visits your website again, the application can retrieve the previously stored information.
C #. Net Section
Cookie creation method (1)
Response. Cookies ["username"]. value = "admin ";
Response. Cookies ["username"]. expires = datetime. Now. adddays (1 );
// If no expiration time is set, the cookie information will not be written to the user's hard disk, and will be discarded if the browser is closed.
Cookie creation method (2)
Httpcookie acookie = new httpcookie ("lastvisit"); // last access time
Acookie. value = datetime. Now. tostring ();
Acookie. expires = datetime. Now. adddays (1 );
Response. Cookies. Add (acookie );
Cookie Access Method (1)
If (request. Cookies ["username"]! = NULL)
Label1.text = server. htmlencode (request. Cookies ["username"]. Value); Cookie Access Method (2)
If (request. Cookies ["username"]! = NULL)
{
Httpcookie acookie = request. Cookies ["username"];
Label1.text = server. htmlencode (acookie. value );
}
Method for creating multi-value cookies (1)
Response. Cookies ["userinfo"] ["username"] = "admin ";
Response. Cookies ["userinfo"] ["lastvisit"] = datetime. Now. tostring ();
Response. Cookies ["userinfo"]. expires = datetime. Now. adddays (1 );
Method for creating multi-value cookies (2)
Httpcookie acookie = new httpcookie ("userinfo ");
Acookie. Values ["username"] = "admin ";
Acookie. Values ["lastvisit"] = datetime. Now. tostring ();
Acookie. expires = datetime. Now. adddays (1 );
Response. Cookies. Add (acookie );
Read multi-value cookies
Httpcookie acookie = request. Cookies ["userinfo"];
String username = acookie. Values ["username"];
String lastvisit = acookie. Values ["lastvisit"];
VB.net
Cookie creation method (1)
Response. Cookies ("username"). value = "admin"
Response. Cookies ("username"). expires = datetime. Now. adddays (1)
'If no expiration time is set, the cookie information will not be written to the user's hard disk and will be discarded if the browser is closed.
Cookie creation method (2)
Dim acookie as httpcookie = new httpcookie ("lastvisit") 'last access time
Acookie. value = datetime. Now. tostring ()
Acookie. expires = datetime. Now. adddays (1)
Response. Cookies. Add (acookie)
Cookie Access Method (1)
If not request. Cookies ("username") is nothing then
Label1.text = server. htmlencode (request. Cookies ("username"). Value) method for accessing cookies (2)
End if
If not request. Cookies ("username") is nothing then
Dim acookie as httpcookie = request. Cookies ("username ")
Label1.text = server. htmlencode (acookie. value)
End if
Method for creating multi-value cookies (1)
Response. Cookies ("userinfo") ("username") = "admin"
Response. Cookies ("userinfo") ("lastvisit") = datetime. Now. tostring ()
Response. Cookies ("userinfo"). expires = datetime. Now. adddays (1)
Method for creating multi-value cookies (2)
Dim acookie as httpcookie = new httpcookie ("userinfo ")
Acookie. Values ("username") = "admin"
Acookie. Values ("lastvisit") = datetime. Now. tostring ()
Acookie. expires = datetime. Now. adddays (1)
Response. Cookies. Add (acookie)
Read multi-value cookies
Dim acookie as httpcookie = request. Cookies ("userinfo ")
Dim username as string = acookie. Values ("username ")
Dim lastvisit as string = acookie. Values ("lastvisit ")
Modify and delete cookies
You cannot directly modify or delete a cookie. You can create only one new cookie and send it to the client to modify or delete the cookie.