cookie不在Google Chrome中工作,而是在Edge等其他浏览器中工作,即

我正在研究 Cookie。之前它可以与所有浏览器一起使用,但现在已停止与 Google Chrome 一起使用,并且仍在与 Edge、IE 等其他浏览器一起使用。

下面是我的代码。

HttpCookie cookie = HttpContext.Current.Request.Cookies["_crt"];
if (cookie == null)
{
    cookie = new HttpCookie("_crt");
    cookie.Path = "/";
    cookie.Expires = DateTime.Now.AddDays(30);
    List<Cart> list = cart.AddItemToCart(cart, new List<Cart>());
    cookie.Value = cart.EncryptCartItem(list);
    HttpContext.Current.Response.Cookies.Add(cookie);

}
else
{
    if (string.IsNullOrWhiteSpace(HttpContext.Current.Request.Cookies["_crt"].Value))
    {
        List<Cart> list = cart.AddItemToCart(cart, new List<Cart>());
        cookie.Value = cart.EncryptCartItem(list);
    }
    else
    { cookie.Value = cart.EncryptCartItem(cart.AddItemToCart(cart, cart.DecryptCartItem(HttpContext.Current.Request.Cookies["_crt"].Value))); }
    cookie.Expires = DateTime.Now.AddDays(30);
    HttpContext.Current.Response.Cookies.Set(cookie);
stack overflow Cookies are not working in Google Chrome but working in other browsers like Edge, IE
原文答案

答案:

作者头像
Response.Cookies.Append("jwt", jwt, new CookieOptions
                    {
                        HttpOnly = true,
                        Secure = true,
                        SameSite = SameSiteMode.None
                    });