บทช่วยสอน ASP

ASP HOME

กวดวิชา WP

แนะนำหน้าเว็บ มีดโกนหน้าเว็บ เค้าโครงหน้าเว็บ โฟลเดอร์หน้าเว็บ หน้าเว็บทั่วโลก แบบฟอร์มหน้าเว็บ วัตถุหน้าเว็บ ไฟล์หน้าเว็บ ฐานข้อมูลหน้าเว็บ ผู้ช่วยหน้าเว็บ หน้าเว็บ WebGrid แผนภูมิหน้าเว็บ อีเมลหน้าเว็บ ความปลอดภัยของหน้าเว็บ เผยแพร่หน้าเว็บ ตัวอย่างหน้าเว็บ ชั้นเรียนของหน้าเว็บ

มีดโกน ASP.NET

แนะนำมีดโกน มีดโกนไวยากรณ์ มีดโกน C# ตัวแปร มีดโกน C# ลูป มีดโกน C# Logic ตัวแปรมีดโกน VB มีดโกน VB Loops มีดโกน VB Logic

ASP Classic

แนะนำ ASP ไวยากรณ์ ASP ตัวแปร ASP ขั้นตอน ASP เงื่อนไข ASP ASP วนรอบ แบบฟอร์ม ASP คุกกี้ ASP เซสชัน ASP แอปพลิเคชัน ASP ASP #รวม ASP Global.asa ASP AJAX อีเมล ASP ตัวอย่าง ASP

การอ้างอิง ASP

ฟังก์ชัน ASP VB คีย์เวิร์ด ASP VB การตอบสนอง ASP คำขอ ASP แอปพลิเคชัน ASP เซสชัน ASP เซิร์ฟเวอร์ ASP ข้อผิดพลาด ASP ASP FileSystem ASP TextStream ไดรฟ์ ASP ไฟล์ ASP โฟลเดอร์ ASP พจนานุกรม ASP ASP AdRotator ASP BrowserCap การเชื่อมโยงเนื้อหา ASP ตัวหมุนเนื้อหา ASP ASP Quick Ref

กวดวิชา ADO

แนะนำ ADO ADO Connect ชุดระเบียน ADO จอแสดงผล ADO แบบสอบถาม ADO ADO Sort เพิ่ม ADO ADO Update ADO ลบ สาธิต ADO ADO เร่งความเร็ว

วัตถุ ADO

คำสั่ง ADO การเชื่อมต่อ ADO ข้อผิดพลาด ADO ADO Field พารามิเตอร์ ADO ADO พร็อพเพอร์ตี้ บันทึก ADO ชุดระเบียน ADO ADO สตรีม ประเภทข้อมูล ADO

ASP Cookies Collection


❮ การอ้างอิงออบเจ็กต์การตอบสนองที่สมบูรณ์

คอลเล็กชันคุกกี้ใช้เพื่อตั้งค่าหรือรับค่าคุกกี้ หากไม่มีคุกกี้ คุกกี้จะถูกสร้างขึ้นและใช้ค่าที่ระบุ

หมายเหตุ:คำสั่ง Response.Cookies ต้องปรากฏก่อนแท็ก <html>

ไวยากรณ์

Response.Cookies(name)[(key)|.attribute]=value

variablename=Request.Cookies(name)[(key)|.attribute]

Parameter Description
name Required. The name of the cookie
value Required for the Response.Cookies command. The value of the cookie
attribute Optional. Specifies information about the cookie. Can be one of the following parameters: 
  • Domain -  Write-only. The cookie is sent only to requests to this domain
  • Expires - Write-only. The date when the cookie expires. If no date is specified, the cookie will expire when the session ends
  • HasKeys - Read-only. Specifies whether the cookie has keys (This is the only attribute that can be used with the Request.Cookies command)
  • Path - Write-only. If set, the cookie is sent only to requests to this path. If not set, the application path is used
  • Secure - Write-only. Indicates if the cookie is secure
key Optional. Specifies the key to where the value is assigned

ตัวอย่าง

คำสั่ง "Response.Cookies" ใช้เพื่อสร้างคุกกี้หรือตั้งค่าคุกกี้:

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

ในโค้ดด้านบนนี้ เราได้สร้างคุกกี้ชื่อ "firstname" และกำหนดค่า "Alex" ให้กับคุกกี้

นอกจากนี้ยังสามารถกำหนดแอตทริบิวต์บางอย่างให้กับคุกกี้ได้ เช่น การตั้งวันที่เมื่อคุกกี้จะหมดอายุ:

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

ตอนนี้คุกกี้ชื่อ "ชื่อ" มีค่าเป็น "อเล็กซ์" และจะหมดอายุจากคอมพิวเตอร์ของผู้ใช้ในวันที่ 10 พฤษภาคม 2545

คำสั่ง "Request.Cookies" ใช้เพื่อรับค่าคุกกี้

ในตัวอย่างด้านล่าง เราดึงค่าของคุกกี้ "ชื่อ" และแสดงบนหน้า:

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

เอาท์พุท:
Firstname=Alex

คุกกี้ยังสามารถมีคอลเล็กชันของค่าต่างๆ ได้หลายค่า เราว่าคุกกี้มีคีย์

ในตัวอย่างด้านล่าง เราจะสร้างคุกกี้คอลเลกชั่นชื่อ "ผู้ใช้" คุกกี้ "ผู้ใช้" มีคีย์ที่มีข้อมูลเกี่ยวกับผู้ใช้:

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

รหัสด้านล่างอ่านคุกกี้ทั้งหมดที่เซิร์ฟเวอร์ของคุณส่งถึงผู้ใช้ โปรดทราบว่ารหัสจะตรวจสอบว่าคุกกี้มีคีย์ที่มีคุณสมบัติ HasKeys หรือไม่:

<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
    Response.Write(x & "=" & Request.Cookies(x) & "<br>")
  end if
  response.write "</p>"
next
%>

</body>
</html>
%>

เอาท์พุท:

firstname=Alex

user:firstname=John
user:lastname=Smith
user:
country=Norway
user:
age=25


❮ การอ้างอิงออบเจ็กต์การตอบสนองที่สมบูรณ์