我正在研究 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);