ASP中Cookie读写的实现方法

80酷酷网    80kuku.com

  cookie|cookiewritecookie.asp

<% Language=VBScript
%>
<%Response.Buffer=true%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>写Cookie的示例</TITLE>
</HEAD>
<BODY>

<%
Response.Write "写Cookie:
"
Response.Cookies("Cookie1")("key1") = "KeyValue1"
Response.Cookies("Cookie1")("key1") = "KeyValue2"
Response.Cookies("Cookie1").Expires = "July 31, 1999"

Response.Cookies("Cookie2")("key2") = "KeyValue1"
Response.Cookies("Cookie2")("key2") = "KeyValue2"
Response.Cookies("Cookie2").Expires = "July 31, 1999"
'Response.Cookies("Cookie2").Path = "/testasp/"
'这个在使用的时候要注意
'是指定在那个目录的文件才可以读取这个cookie的内容。
'在本例子中。只有在testasp这目录下的文件才可以读取
'Cookie2的内容。
%>

</BODY>
</HTML>

-------------------------------------------------------
readwrite.asp

<% Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>读Cookie的示例</TITLE>
</HEAD>
<BODY>

<%Response.Write "读取Cookie:
"

dim cookie,key
  
  for each cookie in Request.Cookies
if Request.Cookies(cookie).haskeys then
Response.Write "
Cookie 名字:"&cookie&"
--------------
"
for each key in Request.Cookies(cookie)

Response.Write "Key 名字:"&key&",值:"&Request.Cookies(cookie)(ke
y)&"
"
next
else
Response.Write "Cookie 名字:"&Request.Cookies(cookie)&"
"
end if
   
  next
   
%>
</BODY>
</HTML>

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: