📜  ASP Request.Cookies 集合(1)

📅  最后修改于: 2023-12-03 15:29:29.447000             🧑  作者: Mango

ASP Request.Cookies 集合

简介

ASP Request.Cookies 集合包含了客户端发送到服务器的所有Cookie。通过这个集合,可以在服务器端读取、设置、删除、以及枚举所有的Cookie。

语法
Request.Cookies(cookieName)
参数

cookieName:要读取的Cookie的名称。它是一个字符串类型的必需参数。

返回值

返回值是一个Cookie对象,包含了请求中的该Cookie的名称、值、过期日期、路径、域以及其它属性。

示例
读取Cookie
Dim myCookie
Set myCookie = Request.Cookies("myCookieName")

If Not myCookie Is Nothing Then
    Response.Write myCookie("myCookieValue")
Else
    Response.Write "Cookie not found!"
End If
设置Cookie
Dim myCookie
Set myCookie = Response.Cookies("myCookieName")

myCookie("myCookieValue") = "MyValue"
myCookie.Expires = Date + 30
myCookie.Path = "/"
myCookie.Domain = ".example.com"
删除Cookie
Dim myCookie
Set myCookie = Response.Cookies("myCookieName")

myCookie.Expires = Date - 1
枚举所有的Cookie
Dim cookieName
For Each cookieName In Request.Cookies
    Response.Write cookieName & " : " & Request.Cookies(cookieName) & "<br>"
Next
参考

ASP Request.Cookies 对象