无法更新/删除Google Chrome C#中的Cookie

时间:2020-07-20 12:07:13

标签: c# asp.net asp.net-mvc google-chrome

我似乎无法使用以下代码在Google chrome上更新Cookie

[HttpPost]
public JsonResult _RemoveFromCart(int id)
{
    var usr = CommonFunctions.GetLoggedUser();
    HttpCookie mycookie = Request.Cookies[Sitesettings.UsersCart + "" + usr.Id];            
    List<Addtocart> lst = new List<Addtocart>();
    if (mycookie != null && !string.IsNullOrEmpty(mycookie.Value))
    {
        string jsn = AESEncryptDecrypt.DecryptAsString(mycookie.Value);
        lst = JsonConvert.DeserializeObject<List<Addtocart>>(jsn);
        var item = lst.SingleOrDefault(x => x.id == id);
        if (item != null && item.id > 0)
        {
            lst.Remove(item);
        }
        string jsnEnc = lst != null && lst.Count > 0 ? JsonConvert.SerializeObject(lst) : "";                
        mycookie.Value = lst != null && lst.Count > 0 ? AESEncryptDecrypt.EncryptAsString(jsnEnc) : "";
        mycookie.Expires = DateTime.Now.AddDays(Sitesettings.CookieExpires);
        Response.Cookies.Add(mycookie);
        List<ProductModel> myret = lst != null && lst.Count > 0 ? CommonFunctions.GetProductsInCart() : new List<ProductModel>();

        var retvalue = lst != null && lst.Count > 0 ? GetCartJson(myret, lst) : Json(new { success = false, itemcount = 0 });
        return retvalue as JsonResult;
    }
    return Json(new { success = false, itemcount = 0 });
}

cookie中的值始终是相同的,并且似乎没有更新,而在调试中,我可以清楚地看到新值。

在Firefox上,它运行良好

0 个答案:

没有答案