我有一个叫做SurveyCookie的cookie.像这样创建:
var cookie = new HttpCookie("SurveyCookie"); cookie.Values["surveyPage"] = "1"; cookie.Values["surveyId"] = "1"; cookie.Values["surveyTitle"] = "Definietly not an NSA Survey...."; cookie.Values["lastVisit"] = DateTime.UtcNow.ToString(); cookie.Expires = DateTime.UtcNow.AddDays(30); Response.Cookies.Add(cookie);
哪个效果很好.现在,当我想像这样更改值"surveyPage"时出现问题.
下面将创建一个新的cookie,这不是我想要的.
int cookieValue = Convert.ToInt32(Request.Cookies["SurveyCookie"]["surveyPage"]) + 1; Response.Cookies["SurveyCookie"]["surveyPage"] = cookieValue.ToString();
然后我尝试下面的代码也不起作用.调查页面仍然是1,应该是2.
Request.Cookies["SurveyCookie"]["surveyPage"] = cookieValue.ToString();
由于上述两种方法都没有改变surveyPage的cookie值?