I have a login link that fires a javascript function that calls a logout page. This is what the logout page consists of:
If Response.Cookies.Count > 0 Then Response.Cookies('aLog').Value = Nothing Response.Cookies.Clear() End If
Originally I just had cookies.clear in there, but that wasn’t working.
Here is the javascript that send the request to the logout 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 function $.cookie does not work either. The cookie is set by ASP.NET, so I figured I could unset it with ASP.NET too but apparently not. Any ideas/suggestions?
Working with cookies in ASP.NET can be a little un-intuitive. To kill a cookie that already lives on the client-side, you have to set its expiration date to sometime in the past, and re-send the client the new cookie. The client browser will update the existing cookie with the new expiration date, and then immediately kill it since it has already passed the expiration date: