Response.Cookies(name)[(key)|.property] = value
Expires 持久化value = Request.Cookies(name)[(key)]
| 屬性 | 說明 |
|---|---|
| Domain | 限定可存取的網域(唯寫) |
| Expires | 過期日期,持久化必設(唯寫) |
| Path | 限定可存取的路徑(預設應用程式路徑) |
| Secure | 僅 HTTPS 傳輸(唯寫) |
| HasKeys | 是否包含子鍵(唯讀) |
表單頁 4-3g.htm:輸入姓名、性別提交
處理頁 4-3g.asp:
<% Response.Buffer = True %>
<%
n = Request.Cookies("User")("VisitedTimes")
name = Request.QueryString("txtuserName")
sex = Request.QueryString("optUserSex")
If n = "" Then n = 1 Else n = n + 1
If sex = "男" Then
Response.Write name & "先生,歡迎光臨!"
ElseIf sex = "女" Then
Response.Write name & "小姐,歡迎光臨!"
End If
Response.Write "本頁面已被訪問 " & n & " 次。"
Response.Cookies("User")("VisitedTimes") = n
Response.Cookies("User").Expires = Date() + 7 ' 7 天有效
%>
用戶關閉 Cookie 時 Session 將失效。IE 6.0 可透過「網際網路選項 → 隱私 → 進階 → 覆蓋自動處理 → 拒絕」停用 Cookie。
Cookie 儲存位置:Win98/Me 為 `C:\Windows\Cookies`,Win2K/XP 為 `C:\Documents and Settings\用戶\Cookies`。