Cookie usage in ASP. NET

Source: Internet
Author: User

Cookie in ASP. NET: Method for creating a Cookie (1)

Cookie in ASP. NET: Method for creating a Cookie (2)

Cookie in ASP. NET: Access Cookie method (1)

Cookie Access Method (2)

You can clear the Cookie by setting the expiration time.

Protected void Page_Load (object sender, EventArgs e) {if (Request. cookies ["nCount"] = null) {// initialize HttpCookie myVale = new HttpCookie ("nCount", "1"); myVale. expires = DateTime. now. addMonths (1); // The cookie folder Response can only be written later than the current time. write ("1"); Response. cookies. add (myVale); // write} else {HttpCookie cookie = Request. cookies ["nCount"]; // extracts cookie information int n = int. parse (cookie. value) + 1; // Save the updated Value HttpCookie myVale = new HttpCookie ("nCount", n. toString (); myVale. expires = DateTime. now. addMonths (1); // if this line of code is not available, the cookies folder cannot be written. // the output value is Response. write (cookie. value); Response. cookies. add (myVale); // re-overwrite (cannot be modified or deleted. to delete it, you can set an expiration date, which will be automatically deleted by the browser )}}


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.