Cookie Storage Data

Source: Internet
Author: User

First, verify whether the cookie contains data in the loading event:

// If the cookie is not empty, the data is filled in text.
If (request. Cookies ["username"]! = NULL ){
This.txt username. Text = request. Cookies ["username"]. value;
This.txt PWD. Text = request. Cookies ["PWD"]. value;

}

Write code in a logon event: it will expire in 10 minutes

String name = this.txt username. text;
String userpwd = this.txt PWD. text;
If (name = "admin" & userpwd = "123 ")
{
Httpcookie cookie1 = new httpcookie ("username", name );
// Set the expiration time
Cookie1.expires = datetime. Now. addminutes (10 );
// Store it in cookies
Response. Cookies. Add (cookie1 );
Httpcookie cookie2 = new httpcookie ("PWD", userpwd );
Cookie2.expires = datetime. Now. addminutes (10 );
Response. Cookies. Add (cookie2 );
Clientscript. registerstartupscript (this. GetType (), "", "alert ('logon successful, data already saved in cookier')", true );

Write code to the deletion event:

// How to delete a cookie stored on the client:
// 1. Create a cookie with the same name as the cookie saved on the client (objective: to overwrite the cookie with the corresponding name on the client)
// 2. Set the cookie expiration time to the current time (objective: to overwrite the cookie with the corresponding name of the client and immediately expire on your own)
// 3. Save the cookie to the client through response

// Suicide Deletion
Httpcookie cookie1 = new httpcookie ("username", null); // overwrite data in the original text box with null
// Set the effective time to the current time
Cookie1.expires = datetime. now;
Response. Cookies. Add (cookie1 );
Httpcookie cookie2 = new httpcookie ("PWD", null );
// Set the effective time to the current time
Cookie1.expires = datetime. now;
Response. Cookies. Add (cookie2 );
Clientscript. registerstartupscript (this. GetType (), "", "alert ('deleted successfully')", true );

 

Cookie Storage Data

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.