我曾在Microsoft Edge中尝试过,其中的cookie更新按预期工作,但不知道为什么Google chrome无法更新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);
我怀疑是由于Google Chrome Samesite设置导致的?