|
bsp; subkeyValue = Server.HtmlEncode(aCookie.Values(j)) output &= "子键名称 = " & subkeyName & "<br>" output &= "子键值 = " & subkeyValue & "<br><br>" Next Else output &= "值 = " & Server.HtmlEncode(aCookie.Value) & "<br><br>" End If Next Label1.Text = output 您也可以把子键作为 NameValueCollection 对象进行提取,如下所示: If aCookie.HasKeys Then Dim CookieValues As _ System.Collections.Specialized.NameValueCollection = aCookie.Values Dim CookieValueNames() As String = CookieValues.AllKeys For j = 0 To CookieValues.Count – 1 subkeyName = Server.HtmlEncode(CookieValueNames(j)) subkeyValue = Server.HtmlEncode(CookieValues(j)) output &= "子键名称 = " & subkeyName & "<br>" output &= "子键值 = " & subkeyValue & "<br><br>" Next Else output &= "值 = " & aCookie.Value & "<br><br>" End If 注意:请记住,我之所以调用 Server.HtmlEncode 方法,只是因为我要在页面上显示 Cookie 的值。如果您只是测试 Cookie 的值,就不必在使用前对其进行编码。 修改和删除 Cookie 有时,您可能需要修改某个 Cookie,更改其值或延长其有效期。(请记住,由于浏览器不会把有效期信息传递到服务器,所以您无法读取 Cookie 的过期日期。) 当然,实际上您并不是直接更改 Cookie。尽管您可以从 Request.Cookies 集合中获取 Cookie 并对其进行操作,但 Cookie 本身仍然存在于用户硬盘上的某个地方。因此,修改某个 Cookie 实际上是指用新的值创建新的 Cookie,并把该 Cookie 发送到浏览器,覆盖客户机上旧的 Cookie。 以下示例说明了如何更改用于储存站点访问次数的 Cookie 的值: Dim counter As Integer If Request.Cookies("counter") Is Nothing Th上一页 [1] [2] [3] 下一页 |
|
|
|
|
|
|
|