Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do delete cookies in asp.net when i close browser ?
Posted

You cannot delete cookies via ASP.Net. This is something that is browser dependent and cannot be done directly.

The best you can do is expire cookies for your website / session.
 
Share this answer
 
Comments
Thắng Cv 10-Jun-13 22:45pm    
tks you so much.i understand
Refer - Clear cookies on browser close[^]
Quote:
Sessions are usualy used for this. According to Wikipedia[^], when no expiration date is set, a cookie is cleared when the user closes the browser.

The cookie setter can specify a deletion date, in which case the cookie will be removed on that date. If the cookie setter does not specify a date, the cookie is removed once the user quits his or her browser.
 
Share this answer
 
As other experts suggested,cookies can not be deleted directly on user's computer,but you can do something tricky e.g. setting the cookie's expiration date to a past date.

C#
if (Request.Cookies["YourCookies"] != null)
{
    Response.Cookies["YourCookiesCookies"].Expires = DateTime.Now.AddDays(-1);
    Response.Redirect("Redirect to xyz.aspx"); 
}


For more information refer to below links

How to: Delete a Cookie[MSDN][^]

Basics of Cookies in ASP.NET[^]
 
Share this answer
 
Comments
Thắng Cv 11-Jun-13 21:44pm    
I see what you mean i tried and success
Cookies is deleted when page loading

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900