I am working on Cookies. It was earlier working with all browsers, but now stopped working with Google Chrome and is still working with other browsers like Edge, IE.
Below is my code.
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);