Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it that my cookie is not getting deleted/unset?

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?

like image 394
Anders Avatar asked Mar 12 '09 13:03

Anders


People also ask

Why do my cookies keep coming back after I delete them?

However, the bad cookies that malware scanners can detect and remove want to try and steal your personal information. If bad cookies keep making their way back onto your company computer after a scanner removes them, it is because your Web browsing keeps inviting the cookie back.

Can not delete cookies?

Click the upper-right hamburger stack and select Options > Privacy & Security. Under Cookies and Site Data, click Clear Data > Cookies and Site Data > Clear to remove your entire cookie history. Back to Cookies and Site Data, select Manage Data if you want to choose the sites from which to remove cookies.

Can you permanently remove cookies?

… on your Android deviceGo to the “Settings” menu. Look for “Privacy & security” and select “Clear private data.” Select “Cookies & active logins.” After you have made your selection, tap “Clear data.”

How do I delete cookies forever?

Settings. Clear browsing data. Choose a time range, like Last hour or All time. Check Cookies and site data and uncheck all other items.


1 Answers

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:

HttpCookie cookie = Request.Cookies["aLog"];
cookie.Expires = DateTime.Now.AddYears(-10);
Response.AppendCookie(cookie);
like image 166
Rex M Avatar answered Nov 14 '22 23:11

Rex M