Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete cookies in asp.net

Tags:

c#

.net

asp.net

I would like to know can we delete cookie from cookies collection what we have created in asp.net website.I tried & find Expiration Logic.It works but it shows in browser cookie.

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

Is there any other way by this we can delete cookies from collection so it will not show in browser cookies.

Please help me to solve the issue.Thanks in advance.

like image 542
PrateekSaluja Avatar asked Jul 05 '11 09:07

PrateekSaluja


People also ask

How do I delete cookies in net?

Cookies cannot be deleted or removed, it can be made to expire by setting its Expiry Date to a Past Date in ASP.Net MVC Razor. Note: For beginners in ASP.Net MVC, please refer my article ASP.Net MVC Hello World Tutorial with Sample Program example.

Which method is used to delete a cookie?

Deleting Cookie: There is no special dedicated function provided in PHP to delete a cookie. All we have to do is to update the expire-time value of the cookie by setting it to a past time using the setcookie() function. A very simple way of doing this is to deduct a few seconds from the current time.

How do I delete cookies in VB net?

A Cookie cannot be removed or deleted, it only can be made expired and hence the Expiry Date of the Cookie is set to a past date and the Cookie is updated back into the Response. Cookies collection. //Fetch the Cookie using its Key.

Does session abandon clear cookies?

Removing a cookie and abandoning a session does not remove the cookie.


1 Answers

From the documentation:

You cannot directly delete a cookie on a user's computer. However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date. The next time a user makes a request to a page within the domain or path that set the cookie, the browser will determine that the cookie has expired and remove it.

So, your strategy is the right one, and the cookie should disappear from the browser once the response is received.

like image 60
Frédéric Hamidi Avatar answered Oct 26 '22 08:10

Frédéric Hamidi