C# HttpCookie-无法更新现有cookie ASP.NET[Google Chrome] 下面的代码用于将值更新到现有cookie中 这些代码工作正常,但现在我不知道它为什么会中断,无法将最新值更新到cookie中。(Cookie继续显示第一个赋值) 流程示例: a) cookie中的第一个赋值是“abc”。 b) 将“123”更新为cookie中的最新值。 c) 读取cookie,但值仍为“abc”
我在微软的Edge上试过,cookie更新的效果和预期的一样,但不知道谷歌chrome为什么不能更新cookieC# HttpCookie-无法更新现有cookie ASP.NET[Google Chrome] 下面的代码用于将值更新到现有cookie中 这些代码工作正常,但现在我不知道它为什么会中断,无法将最新值更新到cookie中。(Cookie继续显示第一个赋值) 流程示例: a) cookie中的第一个赋值是“abc”。 b) 将“123”更新为cookie中的最新值。 c) 读取cookie,但值仍为“abc”,c#,asp.net,google-chrome,httpcookie,samesite,C#,Asp.net,Google Chrome,Httpcookie,Samesite,我在微软的Edge上试过,cookie更新的效果和预期的一样,但不知道谷歌chrome为什么不能更新cookie string m_cookie = FormsAuthentication.FormsCookieName; string m_Json = string.Empty; HttpCookie m_httpCookie; FormsAuthenticationTicket m_ticket; m_httpCookie = System.Web.H
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);
string m_cookie=FormsAuthentication.formscookeName;
string m_Json=string.Empty;
HttpCookie m_HttpCookie;
形式认证票m_票;
m_httpCookie=System.Web.HttpContext.Current.Request.Cookies[m_cookie];
m_ticket=FormsAuthentication.Decrypt(m_httpCookie.Value);
m_Json=(JsonConvert.SerializeObject(新的UserCredential1
{
UserName=“123”,
ExpiredAt=“123”,
AccessToken=“123”,
TokenType=“123”,
})).ToString();
var newticket=新表单身份验证票证(m_ticket.Version,m_ticket.Name,
m_ticket.IssueDate、dtNowAdd1min、false、m_Json、m_ticket.CookiePath);
m_httpCookie.Value=FormsAuthentication.Encrypt(newticket);
如果(newticket.ispersist)m_httpCookie.Expires=newticket.expire;
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结果=JsonConvert.DeserializeObject(m_ticket.UserData);
嘿,我不确定您试图设置或读取cookie的上下文。如果是在第三方/跨站点环境中,则您可能会受到SameSite更改的影响。我们这里有一些Chrome开发工具的调试指南:@rowan_m谢谢,我已经测试了你的链接,并确认了它的相同问题。而现在,由于新冠肺炎爆发,谷歌暂时取消了Chrome对SameSite cookie的要求,cookie突然像以前一样正常工作。您可以在此处签出设置cookie时,您可能需要设置
SameSite=None
和Secure
属性。