ASP中Cookie读写的实现方法

2018-09-06 11:09

阅读:724

  writecookie.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:<br>
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:<br>

  dim cookie,key

for each cookie in Request.Cookies
if Request.Cookies(cookie).haskeys then
Response.Write <br>Cookie 名字:cookie<BR>--------------<BR>
for each key in Request.Cookies(cookie)

  Response.Write Key 名字:key,值:Request.Cookies(cookie)(ke
y)<BR>
next
else
Response.Write Cookie 名字:Request.Cookies(cookie)<BR>
end if

next

%>
</BODY>
</HTML>

  --


评论


亲,登录后才可以留言!