ຄູ່ມື ASP Cookies

ຄູ່ມືອະນຸມັດ Request

ຄູ່ມື Cookies ມີການຕັ້ງຂໍ້ມູນຫຼື ດຶງດູດຂໍ້ມູນຂອງ cookie. ຖ້າ cookie ບໍ່ມີ, ຈະສ້າງມັນຂຶ້ນແລະຕັ້ງຂໍ້ມູນຕາມຄວາມສັ່ງ.

ຄວາມເຫັນ:ການສັ່ງ Response.Cookies ຕ້ອງຢູ່ກ່ອນ <html> ການສັ່ງ.

ວິທີການ:

Response.Cookies(name)[(key)|.attribute]=value
variablename=Request.Cookies(name)[(key)|.attribute]
ປະເພດ ການອະທິບາຍ
name ຄວາມຄິດສົມທຽບ. ປະຫວັດມະນາງຂອງ cookie.
value ຄວາມຄິດສົມທຽບ. ຄວາມມູນຂອງ cookie (ສະເພາະສຳລັບ Response.Cookies).
attribute

ຄວາມຄິດສົມທຽບ. ກໍານົດຂໍ້ມູນຂອງ cookie. ສາມາດເປັນປະເພດຕ່າງໆທີ່ລົງມາລົງນັ້ນ.

  • Domain - ແບບຂຽນພຽງ; cookie ຈະສົ່ງໄປຫາຫົວຂໍ້ທີ່ມາຫານີ້.
  • Expires - ແບບຂຽນພຽງ; ວັນທີສິ້ນສຸດຂອງ cookie. ຖ້າບໍ່ກໍານົດວັນທີ, cookie ຈະສິ້ນສຸດໃນຊຸມຊົນ.
  • HasKeys - ແບບອ່ອນນວນ; ກໍານົດວ່າ cookie ມີ key ຫຼືບໍ່ (ນີ້ແມ່ນປະເພດທີ່ທຳມະດາທີ່ສາມາດໃຊ້ກັບ Response.Cookies).
  • Path - ແບບຂຽນພຽງ; ຖ້າຕັ້ງຂອງກໍານົດ, cookie ຈະສົ່ງໄປຫາຫົວຂໍ້ທີ່ມາຫານີ້. ຖ້າບໍ່ຕັ້ງ, cookie ຈະສົ່ງໄປຫາຫົວຂໍ້ຂອງການບໍລິຫານ.
  • Secure - ແບບຂຽນພຽງ; ຈະຊີ້ໃຫ້ຮູ້ວ່າ cookie ໄດ້ຖືກຮັກສາຄວາມປອດໄພຫຼືບໍ່.
key ຄວາມຄິດສົມທຽບ. ກໍານົດບ່ອນທີ່ຈະຕັ້ງຂໍ້ມູນບ່ອນຫວັງ.

ຕົວຢ່າງ

"Response.Cookies" ການສັ່ງຂອງ cookie ຫຼື ຕັ້ງຂໍ້ມູນວ່າ cookie:

<%
Response.Cookies("firstname")="Alex"
%>

ໃນລະຫັດການທີ່ມີຢູ່ບໍລິໂພກພາຍໃນຄຳສັ່ງ "firstname" ພວກເຮົາຈະຕັ້ງຂໍ້ມູນວ່າ alex .

ກໍ່ສາມາດຕັ້ງປະສົງຂອງ cookie ຕາມຄວາມຫວັງ ອອກຈາກວັນນີ້:

<%
Response.Cookies("firstname")="Alex" 
Response.Cookies("firstname").Expires=#May 10,2002#
%>

ປັດຈຸບັນ cookie ທີ່ມີຊື່ "firstname" ມີຄູ່ມີ "Alex" ແລະ ມີວັນສະຕິກັນສູນຂອງມັນໃນຄອມພິວເຕີ້ຂອງ user ໃນວັນທີ 10 ພຶດສະພາ 2002 .

"Request.Cookies" ສຽງສັ່ງສາມາດເອົາຄູ່ມີຫຼັງ .

ໃນຄັນຄືນດັ່ງລຽງນີ້ພວກເຮົາໄດ້ເອົາຄູ່ມີ "firstname" ແລະ ສະແດງມັນໃນໜ້າເວັບ :

<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>

ການສະແດງອາກາດ

Firstname=Alex

cookie ສາມາດມີຄູ່ມີຫຼາຍຄວາມຄືບໜຶ່ງ . ພວກເຂົາເອີ້ນວ່າ cookie ມີ key .

ໃນຄັນຄືນດັ່ງລຽງນີ້ພວກເຮົາຈະສ້າງ cookie ທີ່ມີຊື່ "user" . "user" cookie ມີ key ທີ່ບັນຈຸຂໍ້ມູນຂອງ user .

<%
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Adams"
Response.Cookies("user")("country")="UK"
Response.Cookies("user")("age")="25"
%>

ລະບັບທີ່ຖືກຂຽນສາມາດອ່ານຄວາມຂອງ cookie ທີ່ server ໄດ້ສົ່ງໄປໃຫ້ user . ຍັງມີ HasKeys ທີ່ພິຈາລະນາວ່າ cookie ມີ key ຫຼືບໍ່ :

<html>
<body>
<%
dim x,y
for each x in Request.Cookies
  response.write("<p>")
  if Request.Cookies(x).HasKeys then
    for each y in Request.Cookies(x)
      response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
      response.write("<br /")
    next
  else
    ການຂຽນຄູ່ມີຄຳສັ່ງ x & "=" & Request.Cookies(x) & "<br />"
  end if
  response.write "</p>"
next
%>
</body>
</html>
%>

ການສະແດງອາກາດ

firstname=Alex
user:firstname=John
user:lastname=Adams
user:
country=UK
user:
age=25

ຄູ່ມືອະນຸມັດ Request