我的cookie正在第一頁的頁面上填充值。 但是,當我嘗試通過下面的代碼使用另一個值更新它,然後刷新頁面時,它僅顯示初始值。 爲什麼我不能更新cookie?無法將附加值添加到cookie
If Request.Cookies("lastviewed") Is Nothing Then
Dim cookie As HttpCookie = New System.Web.HttpCookie("lastviewed", Request.RawUrl + "|" + photo + "|" + title + "|" + price)
HttpContext.Current.Response.Cookies.Add(cookie)
Else
lastviewed = Server.UrlDecode(Request.Cookies("lastviewed").Value)
If Not lastviewed.Contains(Request.RawUrl + "|") Then
If lastviewed.Split(";").Length < 5 Then
If lastviewed.Split(";").Length > 0 Then
lastviewed = lastviewed + ";" + Request.RawUrl + "|" + photo + "|" + title + "|" + price
Else
lastviewed = Request.RawUrl + "|" + photo + "|" + title + "|" + price
End If
'this part where I want to ADD a new value to the cookie does not seem to work
Dim cookie As New System.Web.HttpCookie("lastviewed", lastviewed)
HttpContext.Current.Response.Cookies.Add(cookie)
End If
End If
End If
** lastviewed.Contains(Request.RawUrl +「|」)**,它總是如此。 –
@AngusChung爲什麼?這是一個檢查,如果當前頁面已經在cookie中,如果不是,我繼續並添加它。這並非總是如此,那麼對嗎?如果即使它總是如此,至少我應該看到值被添加到cookie。 – Flo
「它只顯示初始值」,初始值是多少? –