The Path to Happy Cookie Deletion

Recently ran into an issue trying to remove a cookie.
Using the web developer tool this was clearly visible in client, and in the ASP.NET code behind this also showed up nicely in the Request.Cookies collection.
So used code like this: http://msdn.microsoft.com/en-us/library/ms178195.aspx to try and delete it.
But amazingly did not work.
Turns out that the path of the cookie was set. This limits it to pages below that path – however, in the Request.Cookies collection the path just came through as “/” – so using the above MSDN code did not clear this.
Copying the cookie from the collection, setting the Path property to the same value displayed in the Web Developer Toolbar, and only then setting the Expires to yesteryear and adding to the Response.Cookies collection – made this work.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: