0

Here is my get:

protected string Identifier
{
    get
    {
        HttpCookie cookie = Request.Cookies[IDENTIFIER_COOKIE];

        if (cookie != null)
        {
            return cookie.Value;
        }
        else
        {
            cookie = new HttpCookie(IDENTIFIER_COOKIE);
            cookie.Value = Guid.NewGuid().ToString();
            cookie.Expires = DateTime.Now.AddYears(1);
            Response.Cookies.Add(cookie);

            return cookie.Value;
        }
    }
}

When running my project locally, the cookie's expiry date is set as expected

local

But when I run it live, the cookie's expiry date is When the browsing session ends.

live

What am I doing wrong?

Community
  • 1
  • 1
Arthur Rey
  • 2,990
  • 3
  • 19
  • 42

2 Answers2

1

The problem was that my page was served on HTTPS. I had to specifiy cookie.Secure = true for the expiry date to be set.

Arthur Rey
  • 2,990
  • 3
  • 19
  • 42
0

Before doing anything else, I suggest that you clear your cache and cookies.

protected string Identifier
{
    get
    {
        HttpCookie cookie = Request.Cookies[IDENTIFIER_COOKIE];

        if (!cookie)
        {
            cookie = new HttpCookie(IDENTIFIER_COOKIE);
            cookie.Value = Guid.NewGuid().ToString();
        }Cookie.Expires = DateTime.Now.AddYears(1);
        Response.Cookies.Set(cookie);

        return cookie.Value
    }
}
SiNONiMiTY
  • 675
  • 3
  • 14