请教cookie更新滞后问题
以下是cookie的更新:
HttpCookie Cookie = new HttpCookie( "ShoppingCook ");
Cookie[ "ProId "] = HttpContext.Current.Request.Cookies[ "ShoppingCook "][ "ProId "].ToString() + ", " + shoppingbag.ProId;
Cookie[ "Nums "] = HttpContext.Current.Request.Cookies[ "ShoppingCook "][ "Nums "].ToString() + ", " + shoppingbag.Nums;
HttpContext.Current.Response.AppendCookie(Cookie);
在更新后取不到最近的一次更新,等到下次再更新时候显示的是上一次的,总之是滞后一次
------解决方案--------------------更新之后,需要使用使用当前数据的,你可以直接变量传送。
------解决方案--------------------不知道 楼主 是否 是使用了缓存
或者其他地方有代码逻辑错误
如果没有
可以 试下 先取出 以前cookie的值并将其删除 然后重新输出
HttpCookie Cookie = Request.Cookies[ "ShoppingCook "];
string ProId = Cookie[ "ProId "];
string Nums = Cookie[ "Nums "];
Cookie.Expires=DateTime.Now.AddDays(-1);
Response.Cookies.Add(Cookie);
Cookie = new HttpCookie( "ShoppingCook ");
Cookie[ "ProId "] = ProId + ", " + shoppingbag.ProId;
Cookie[ "Nums "] = Nums + ", " + shoppingbag.Nums;
Response.AppendCookie(Cookie);