Why is my cookie not deleted / not set?

I have a login link that runs a javascript function that calls the exit page. This is the logout page:

If Response.Cookies.Count > 0 Then Response.Cookies("aLog").Value = Nothing Response.Cookies.Clear() End If 

Initially, I just had cookies.clear, but that didn't work.

Here is the javascript that sends the request to the exit page:

 <script type="text/javascript"> //<![CDATA[ $(document).ready(function() { $('#logout-link').click(function() { if (confirm("Really log out?")) { $.cookie('aLog', null); location.href = $(this).attr('href'); } return false; }); }); //]]> </script> 

The jQuery $.cookie does not work either. The cookie is configured on ASP.NET, so I decided that I could turn it off with ASP.NET, but apparently not. Any ideas / suggestions?

+6
jquery cookies
source share
2 answers

Working with cookies in ASP.NET can be a bit unintuitive. To kill a cookie that already exists on the client side, you must set the expiration date in the past and resend the client a new cookie. The client browser will update the existing cookie with a new expiration date, and then immediately kill it, since it has already expired:

 HttpCookie cookie = Request.Cookies["aLog"]; cookie.Expires = DateTime.Now.AddYears(-10); Response.AppendCookie(cookie); 
+10
source share

In addition to what Rex said, you should always set "the path to any cookie you use (usually something like" / "). Otherwise, the visibility of the cookie depends on the name of the folder in the URL, therefore, if you have anything other than a flat configuration of the URL scheme, and deleting cookies will work very unpredictably.

+4
source share

All Articles