Basic examples of cookies reading and writing

Source: Internet
Author: User
Tags generator visual studio

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:
"
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&"<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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.