Asp.net uses cookies to save user passwords for automatic logon. asp. netcookie

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.