我花了很多时间在这上面,这太疯狂了。
我有一个页面基类,其中包含“setcookie”函数,基本上是这样的:
Dim context As HttpContext = System.Web.HttpContext.Current
If context.Request.Cookies(cookieName) Is Nothing Then
Dim cookie As HttpCookie
cookie.Value = cookieValue
cookie.Expires = DateTime.Now.AddDays(7)
context.Response.Cookies.Add(cookie)
Else
Dim cookie As HttpCookie = context.Request.Cookies(cookieName)
cookie.Expires = DateTime.Now.AddDays(7)
cookie.Value = cookieValue
End If
该函数由一个简单的 aspx 页面调用。由于这是在测试环境中,所以我正在使用的 cookie 中的先前值为“123”。如果我使用调试和监视窗口,我会看到值成功更改为“168”。
我在一行上有一个调试断点:
Response.Redirect("overview.aspx", False)
当断点处于活动状态时,监视窗口中的值为:
currProjectID 168 Integer
HttpContext.Current.Request.Cookies("currProjectID").Value "168" String
(currProjectID是basepage类中的一个属性,它使用上面的函数获取/设置cookie)
现在,当我使用“F10”离开上面的断点行时,变量的值发生了变化!
HttpContext.Current.Request.Cookies("currProjectID").Value "123" String
currProjectID 123 Integer
疯了吧!代码无处可去,调试点就在上面的“response.redirect”行下方,但值已立即更改为之前的值!没有任何事情接近“setcookie”例程,所以请有人拯救我的疯狂并告诉我出了什么问题!?