Shortcuts

how to delete cookies?

Hi,
I am creating a cookie using the following code:
Dim iharyanacookie As HttpCookie
iharyanacookie = New HttpCookie("username", uid.Text)
Response.Cookies.Add(iharyanacookie)

But how can I delete or destroy a cookies. I using the following code about cookies is still there and working.
Response.Cookies("iharyanacookie").Expires = DateTime.Now.AddYears(-30)
Response.Cookies.Remove("iharyanacookie")
Response.Redirect("http://www.iharyana.com")

Re: how to delete cookies?

Deleting Cookies

<div class=subsection>

Deleting a cookie—physically removing it from the user's hard disk—is a variation on modifying it. You cannot directly remove a cookie because the cookie is on the user's computer. However, you can have the browser delete the cookie for you. The technique
is to create a new cookie with the same name as the cookie to be deleted, but to set the cookie's expiration to a date earlier than today. When the browser checks the cookie's expiration, the browser will discard the now-outdated cookie. The following code
example shows one way to delete all the cookies available to the application:

Re: how to delete cookies?

Thanks for all your help i just have one suggestion that without creating a new cookie with same name we can also take instance of already existing cookie[As we are going to delete a cookie so it must exist :)] and then set its expires date and set it back
in response...for PoC i have created one static function which you can use by just passing the cookie name to delete. Here it is :