Clearing cookies in Asp.net

Source: Internet
Author: User
I used cookies to save the user ID when I log on to the system. However, there was a small problem when I exited.

Code
Response. Cookies. Clear ()

However, when you exit, you still cannot exit. Cookies are still present! I was puzzled at the beginning.CodeThe prompt in is to clear all cookies in the set, but why is it still there? I checked the information and said that it was necessary to set the expiration time. I changed the code again.
 

Code
  Foreach (Httpcookie cookie In Response. Cookies)
{
Cookie. Expires = Datetime. Today. adddays ( - 5 );
Response. Cookies. Remove (cookie );
}

After the modification, the cookies are still in progress. last found for half a day, originally response. cookies. clear () only clears cookies that are now added to response. client Cookies cannot be cleared. after changing the code, you can finally

 

Code
Foreach ( String Cookiename In Request. Cookies. allkeys)
{
Httpcookie = Request. Cookies [cookiename];
Cookie. Expires = Datetime. Today. adddays ( - 5 );
Response. Cookies. Add (cookie );
}

This problem may not be noticed during normal use!

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.