How to delete cookies in asp.net

I would like to know if we can remove the cookie from the cookie collection that we created on the asp.net website. I tried to find Expiration Logic.It works, but it displays in the cookie browser.

Response.Cookies["UserID"].Expires = DateTime.Now.AddDays(-1); 

Is there any other way, we can remove cookies from the collection so that it does not appear in browser cookies.

Please help me solve the problem. Thanks in advance.

+8
source share
2 answers

From the documentation :

You cannot directly delete a cookie on a user's computer. However, you can direct the user browser to delete cookies by setting the cookie expiration date to the last date. The next time the user makes a request for pages in the domain or path that the cookie sets, the browser will determine that the cookie has expired and delete it.

So, your strategy is correct, and the cookie should disappear from the browser after receiving a response.

+8
source share

I am not sure that you can delete the cookie, since you do not have access to delete anything on the client computer. All you can do is basically what you do is the invalidity of the cookie for your application. I think the client software will decide whether to delete the cookie or not, all you can do is set the timestamp as you do, which means that you will no longer accept this cookie.

0
source share

All Articles