Hướng dẫn ASP

TRANG CHỦ ASP

Hướng dẫn WP

Giới thiệu trang web Dao cạo trang web Bố cục trang web Thư mục Trang web WebPages Global Biểu mẫu trang web Đối tượng trang web Tệp trang web Cơ sở dữ liệu trang web Người trợ giúp Trang web WebPages WebGrid Biểu đồ trang web Email các trang web Bảo mật trang web Xuất bản trang web Ví dụ về trang web Các lớp trang web

ASP.NET Razor

Giới thiệu Razor Cú pháp dao cạo Các biến Razor C # Dao cạo C # Vòng Dao cạo C # Logic Biến VB Razor Vòng lặp VB Razor Razor VB Logic

ASP cổ điển

Giới thiệu ASP Cú pháp ASP Biến ASP Thủ tục ASP Điều kiện ASP ASP Looping Biểu mẫu ASP ASP Cookies Phiên ASP Ứng dụng ASP ASP #include ASP Global.asa ASP AJAX ASP e-mail Ví dụ về ASP

Tham chiếu ASP

Chức năng ASP VB Từ khóa ASP VB Đáp ứng ASP Yêu cầu ASP Ứng dụng ASP Phiên ASP Máy chủ ASP Lỗi ASP ASP FileSystem Dòng văn bản ASP Ổ ASP Tệp ASP Thư mục ASP Từ điển ASP ASP AdRotator ASP BrowserCap Liên kết nội dung ASP Công cụ xoay vòng nội dung ASP Tham khảo nhanh ASP

Hướng dẫn ADO

Giới thiệu ADO Kết nối ADO ADO Recordset Hiển thị ADO Truy vấn ADO ADO Sắp xếp ADO Thêm Cập nhật ADO ADO Xóa ADO Demo Tăng tốc ADO

Đối tượng ADO

Lệnh ADO Kết nối ADO Lỗi ADO Trường ADO Tham số ADO ADO thuộc tính Bản ghi ADO ADO Recordset Luồng ADO ADO DataTypes

Bộ sưu tập cookie ASP


❮ Tham chiếu đối tượng phản hồi hoàn chỉnh

Bộ sưu tập Cookie được sử dụng để đặt hoặc lấy các giá trị cookie. Nếu cookie không tồn tại, nó sẽ được tạo và lấy giá trị được chỉ định.

Lưu ý: Lệnh Response.Cookies phải xuất hiện trước thẻ <html>.

Cú pháp

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

Các ví dụ

Lệnh "Response.Cookies" được sử dụng để tạo cookie hoặc đặt giá trị cookie:

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

Trong đoạn mã trên, chúng tôi đã tạo một cookie có tên "firstname" và gán giá trị "Alex" cho nó.

Cũng có thể chỉ định một số thuộc tính cho cookie, chẳng hạn như đặt ngày khi cookie sẽ hết hạn:

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

Bây giờ cookie có tên "firstname" có giá trị là "Alex" và nó sẽ hết hạn trên máy tính của người dùng vào ngày 10 tháng 5 năm 2002.

Lệnh "Request.Cookies" được sử dụng để lấy giá trị cookie.

Trong ví dụ bên dưới, chúng tôi truy xuất giá trị của cookie "firstname" và hiển thị nó trên một trang:

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

Đầu ra:
Firstname=Alex

Một cookie cũng có thể chứa một tập hợp nhiều giá trị. Chúng tôi nói rằng cookie có Chìa khóa.

Trong ví dụ dưới đây, chúng tôi sẽ tạo một bộ sưu tập cookie có tên là "người dùng". Cookie "người dùng" có các Khóa chứa thông tin về người dùng:

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

Đoạn mã dưới đây đọc tất cả cookie mà máy chủ của bạn đã gửi cho người dùng. Lưu ý rằng mã kiểm tra xem cookie có Khóa với thuộc tính HasKeys hay không:

<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>
%>

Đầu ra:

firstname=Alex

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


❮ Tham chiếu đối tượng phản hồi hoàn chỉnh