0

From a C# page, I can't delete a cookie on Firefox and Internet Explorer. I use the Expires changing method with works perfectely from on a Chrome browser...

I founs many way to delete cookies on the Internet, and in a last chance try, I execute them like this :

  protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            Response.Cookies["CDV_Id_User"].Value = "-1";
        }
        catch
        {

        }

        try
        {
            Request.Cookies["CDV_Id_User"].Value = "-1";
        }
        catch
        {

        }
        try
        {
            Response.Cookies["CDV_Id_User"].Expires = DateTime.Now.AddDays(-1);
        }
        catch
        {

        }
        try
        {
            Request.Cookies["CDV_Id_User"].Expires = DateTime.Now.AddDays(-1);
        }
        catch
        {

        }

        try
        {
            HttpContext.Current.Session.Abandon();
        }
        catch { }

        try
        {
            HttpContext.Current.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
        }
        catch { }

        Session["id_user"] = null;

        Response.Redirect("~/Default.aspx", false);
    }

But even with execution of such many way to make the cookie CDV_Id_User expire, this NEVER works on Firefox... but only on Chrome...

HELP please ! :-)

user1592596
  • 65
  • 1
  • 10
  • Have you seen this? http://stackoverflow.com/questions/4205534/firefox-not-deleting-cookies?rq=1 Which refs this: http://stackoverflow.com/questions/777767/firefox-session-cookies – Wjdavis5 Apr 03 '16 at 18:01
  • I will check that point. However, the problem is that the code must work even if the tab enabled option is active ... ? Do you have a solution to be able to delete a cookie in these conditions ? – user1592596 Apr 04 '16 at 08:58

1 Answers1

0

Do you have Firefox's save your tabs enabled?

Firefox not deleting cookies

Firefox session cookies

Try disabling saving of tabs and firefox should clear things out when closed etc.

Wjdavis5
  • 3,952
  • 7
  • 35
  • 63
  • That's right, when I first close the tab where my cookie was declared (and so deleted), that works. The problem is for my customers : they don't have to know this "procedure"... is there a solution to delete cookie, even with this Firefox behaviour ? Thanks :) – user1592596 Apr 10 '16 at 08:38
  • Sure. You'll just have to ignore cookies older than X on the server side. – Wjdavis5 Apr 10 '16 at 10:51
  • The problem is that I use this method to save the identity of my users, when thay check the "remember me" checkbox. So, I need to have a "disconnect button" which delete the cookie by modifying the expiration date... if I ignore cookies older than X we don't have the possibility to disconnect before X time :( – user1592596 Apr 10 '16 at 18:03
  • So just append an element to the cookie : isDisconnected = true that gets set when they choose to disconnect. – Wjdavis5 Apr 13 '16 at 13:34
  • The problem is, that the cookie is never updated : if I set the value to "-1" with : Response.Cookies["CDV_Id_User"].Value = "-1"; the value of the cookie remain as it is... actually, when the cookie is created, it's impossible to change the value, or change, the expiry date... it's uncomprehensible ! – user1592596 Apr 13 '16 at 19:36