Asp.net uses cookies to save user passwords for automatic logon. asp. netcookie
This example describes how asp.net uses cookies to save user passwords for automatic logon. Share it with you for your reference. The specific analysis is as follows:
In asp.net, you can use cookies to save your account and password for automatic logon. However, it is not secure to store cookies on the client. We recommend that you use md5 encryption to save them.
The following describes how to create, extract, and destroy cookies in asp.net:
Create cookie
Copy codeThe Code is as follows: // write a Cookie to the client
HttpCookie hcUserName1 = new HttpCookie ("uname"); // create a cookie named uname
HcUserName1.Expires = DateTime. Now. AddDays (7); // set the cookie Validity Period
HcUserName1.Value = uname; // assign a value to the cookie (that is, the account or password you want to save)
HttpContext. Current. Response. Cookies. Add (hcUserName1); // submit the cookie
Extract cookie
Copy codeThe Code is as follows: if (HttpContext. Current. Request. Cookies ["uname"]! = Null) // if this uname cookie is not empty
String uname = HttpContext. Current. Request. Cookies ["uname"]. Value. ToString (); // extract cookie
Destroy cookie
Copy codeThe Code is as follows: // set the cookie time to-1, that is, the cookie expires and is destroyed.
HttpContext. Current. Response. Cookies ["uname"]. Expires = DateTime. Now. AddSeconds (-1 );
I hope this article will help you design your asp.net program.