15-4 設?小??

Response.CookiesiHΨӳ]wΤݪp氮C@Ӥp氮 Name ӨAResponse.Cookies(Name) UCʽG
Response.Cookies(Name) ʽC
ʽ
Expiresw Cookies ƪĴ
Domain Cookies sbSw Domain U
Path Cookies sbSw|U
Secure Ȱ쬰 True FalseAN Cookies ƬO_H SSL (Secure Socket Layer) 覡ǰe

UO@Өϥ Cookies 򥻽dG

Example]response/cookie01.asp^G

bWzdҤAunLjWAN|ܤWӳXɶAWzdҪlɮצpUG

lɡ]response/cookie01.asp^G]ǦϰUYi^
<%@Language=JScript%>
<%
now = new Date();
expDate = new Date();
expDate.setTime(now.getTime()+365*24*60*60*1000);	// ƱNQOd@~	
x = Request.Form("userName")+"";
if (x!="undefined"){		// ѪIӸJ ==> ]wp氮
	Response.Cookies("userName") = Request("userName");
	Response.Cookies("userName").Expires = expDate.getVarDate();	// ϥ getVarDate() NƫAন VARIANT
	Response.Cookies("userTime") = now.toLocaleString();
	Response.Cookies("userTime").Expires = expDate.getVarDate();	// ϥ getVarDate() NƫAন VARIANT
}
%>
<% title = "ϥ Cookie 򥻽d"; %>
<!--#include file="../head.inc"-->
<hr>

<%
userName = Request.Cookies("userName")+"";	// op氮ҰO userName T 
if (userName == ""){ %>
	znOĤ@yXIжJzjWA¡I
<% } else { %>
	<%=userName%></font> znI
	<br>zWnɶ <%=Request.Cookies("userTime")%>C
	<br>pGzjWO <%=userName%>AЭsnC
<% } %>

<form method=post>
jWG<input name="userName"> <input type=submit>
</form>
]zJTN|QOdbzwФ CookiesAOd@~C^

<hr>
<!--#include file="../foot.inc"-->

pW@`ҭzAѩ Request.Cookies O@ Dictionary ܼơAҥHڭ̥iH䤺ei@@CAҦpG

Example]response/listCookie01.asp^G

WzdҪlɮצpUG

lɡ]response/listCookie01.asp^G]ǦϰUYi^
<%@Language=JScript%>
<%
Response.Cookies("111") = "x_";
Response.Cookies("222") = "";
%>
<% title = "H JScript LX Request.Cookies e" %>
<!--#include file="../head.inc"-->
<hr>

<!--#include file="../listdict.inc"-->
<% listdict(Request.Cookies, "Request.Cookies"); %>

<hr>
<!--#include file="../foot.inc"-->

bWzdҤAڭ̥iHݥXA@ڭ̳]w Response.CookiesA Request.Cookies ]|ߨQﱼAoOSOBC

Request.Cookies M Response.Cookies Name-Value PairsAXISOn`NG

  1. Request.Cookies Oק諸AAu Response.Cookies i]wMקC
  2. ]w Response.Cookie eAResponse.Cookies M Request.Cookies 㦳ۦP NamesC
  3. @]w Response.CookiesAsWέק諸 Name M Value |ߨQ Request.CookiesAP Response.Cookies Value ]|QMšC
ҤWzĤGBTIAШUCdҡG

Example]response/listCookie02.asp^G

WzdҪlɮצpUG

lɡ]response/listCookie02.asp^G]ǦϰUYi^
<%@Language=JScript%>
<%Response.buffer=true%>
<% title = "Request.Cookies M Response.Cookies e" %>
<!--#include file="../head.inc"-->
<hr>

<!--#include file="../listdict.inc"-->
]w Response.Cookie eG
<p><% listdict(Request.Cookies, "Request.Cookies"); %>
<p><% listdict(Response.Cookies, "Response.Cookies"); %>

<%
// JAC]wsp氮
today = new Date();
todayStr = today.toLocaleString();
Response.Cookies(todayStr) = todayStr;
%>

]w Response.Cookie G
<p><% listdict(Request.Cookies, "Request.Cookies"); %>
<p><% listdict(Response.Cookies, "Response.Cookies"); %>

<hr>
<!--#include file="../foot.inc"-->

򥻤WACookies Og HTTP Header ӶǰeCΤݦVAnDɡAƹWoӰeA Request N]t۩M CookiesA]AiHھڳoǸTAӫإߥX Request.Cookies CAneΤݮɡAbǰeeeA|ǰeY]Header^μDTAH Response.Cookies ҳ]w Cookies eANOQbY]D^TA@_QeΤݡCpG Response.Buffer Q]w falseAӥBA ASP eXeAMAϥ Response.Cookies ӳ]w CookiesAN|ot~TAdҦpUG

Example]response/cookie02.asp^G

bWzdҤAѩ Response.Cookies ]wOX{beAѩ Response.Buffer Q]w FalseAҥH@A}leXTANiAǰe Cookie YTAҥH~|ͤWz~TCWzdҪlɮצpUG

lɡ]response/cookie02.asp^G]ǦϰUYi^
<%@Language=JScript%>
<% Response.buffer = false %>
<% title = "Ϳ~ Cookie ϥνd" %>
<!--#include file="../head.inc"-->
<hr>

<p>oOeC
<p><!--#include file="../foot.inc"-->
<p>HUխקYTANy~...
<% Response.Cookies("xyz") = "abc"; %>

<hr>
<!--#include file="../foot.inc"-->

Hint
Response.Buffer w]ȳq`O trueAOA]iHqA]w令 falseC]FOI_Aڭ̳̦nn̿w]ȡAӪb ASP {X]wڭ̩ҭnȡC

YnקK~o͡A򥻤WؤkG

  1. beXeeA Response.Cookies OCШd example/response/cookie03.aspC
  2. ]w Response.Buffer TrueATOeewİϫAAANYTκe@_eΤݡCШd example/response/cookie04.aspC ]ݪ`NOAResponse.Buffer=True bX HTML eC^
Cookies YS]wĴAh Cookies usbΤݪOANHsӮCpGڭ̦]w Cookies ĴAh Cookies N|QgJΤݪwСC~Ab]wĴAP@xqhs]Ҧph IE^|ݨP@ CookiesAYS]wĴAh Cookies uݩSwY@sC~AUas Cookies 䴩覡礣ɬۦPAGLk@ΡC
JScript {]pPΡGΩAݪ ASP