Asp.net cookie clearing code

Source: Internet
Author: User

Request. Cookies. Clear () is not used to delete cookies.

Deleting a cookie (that is, physically removing a cookie from a user's hard disk) is a form of cookie modification.
The cookie cannot be directly removed because it is on the user's computer.
However, the browser can delete cookies for you.
This technology creates a new cookie with the same name as the cookie to be deleted,
Set the cookie expiration date to a date earlier than the current date.
When the browser checks the cookie expiration date, the browser will discard the expired cookie.
The followingCodeExample: delete an applicationProgramOne method for all available cookies in:Copy codeThe Code is as follows: 1. httpcookie acookie;
2. String cookiename;
3. Int Limit = request. Cookies. count;
4. For (INT I = 0; I <limit; I ++)
5 .{
6. cookiename = request. Cookies [I]. Name;
7. acookie = new httpcookie (cookiename );
8. acookie. expires = datetime. Now. adddays (-1 );
9. response. Cookies. Add (acookie );
10 .}

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.