HttpCookie - Unable to update existing cookie ASP.NET [Google Chrome]

Viewed 770
  1. Codes below is to update value into existing cookie.
  2. These codes working fine but now the I have no idea why it breaks and unable to update the latest value into cookie. (Cookie keep showing first assigned value).
  3. Example flows: a) The first assigned value in cookie is "abc". b) Update "123" as latest value into cookie. c) Read cookie but value remains "abc".
  4. I have tried in Microsoft Edge where the cookie updates worked as expected but no idea why google chrome is failed to update cookie.

        string m_cookie = FormsAuthentication.FormsCookieName;
        string m_Json = string.Empty;
        HttpCookie m_httpCookie;
        FormsAuthenticationTicket m_ticket;
        m_httpCookie = System.Web.HttpContext.Current.Request.Cookies[m_cookie];
        m_ticket = FormsAuthentication.Decrypt(m_httpCookie.Value);
    
        m_Json = (JsonConvert.SerializeObject(new UserCredential1
        {
            UserName = "123",
            ExpiredAt = "123",
            AccessToken = "123",
            TokenType = "123",
        })).ToString();
    
        var newticket = new FormsAuthenticationTicket(m_ticket.Version, m_ticket.Name, 
        m_ticket.IssueDate, dtNowAdd1min, false, m_Json, m_ticket.CookiePath);
        m_httpCookie.Value = FormsAuthentication.Encrypt(newticket);
        if (newticket.IsPersistent) m_httpCookie.Expires = newticket.Expiration;
    
        System.Web.HttpContext.Current.Response.Cookies.Set(m_httpCookie);
    
        m_httpCookie = System.Web.HttpContext.Current.Request.Cookies[m_cookie];
        m_ticket = FormsAuthentication.Decrypt(m_httpCookie.Value);
        UserCredential result = JsonConvert.DeserializeObject<UserCredential>(m_ticket.UserData);
    
  5. I'm suspecting this happens due to Google Chrome Samesite settings?

  6. Anyone have idea about this? Thanks in advance.
0 Answers
Related