Bộ sưu tập Contents ASP

Sách tham khảo đối tượng Application

Bộ sưu tập Contents chứa tất cả các mục được thêm vào application/session thông qua lệnh kịch bản.

Lưu ý:Để xóa bỏ mục từ bộ sưu tập Contents, hãy sử dụng phương thức Remove và RemoveAll.

Cú pháp

Application.Contents(Key)
Session.Contents(Key)
Tham số Mô tả
key Bắt buộc. Tên của mục cần lấy lại.

Đối với đối tượng Application

Ví dụ 1

Lưu ý, name và objtest sẽ được thêm vào bộ sưu tập Contents:

<% 
Application("name")="W3School"
Set Application("objtest")=Server.CreateObject("ADODB.Connection")
%>

Ví dụ 2

Duyệt qua bộ sưu tập Contents:

<%
for each x in Application.Contents
  Response.Write(x & "=" & Application.Contents(x) & "<br />")
next
%>

hoặc:

<%
For i=1 to Application.Contents.Count
  Response.Write(i & "=" & Application.Contents(i) & "<br />")
Tiếp theo
%>

Ví dụ 3

<%
Application("date")="2001/05/05"
Application("author")="W3School"
for each x in Application.Contents
  Response.Write(x & "=" & Application.Contents(x) & "<br />")
next
%>

Kết quả xuất ra:

date=2001/05/05
tác giả=W3School

Đối với đối tượng Session

Ví dụ 1

Lưu ý, name và objtest sẽ được thêm vào bộ sưu tập Contents:

<% 
Session("name")="Hege"
Set Session("objtest")=Server.CreateObject("ADODB.Connection")
%>

Ví dụ 2

Duyệt qua bộ sưu tập Contents:

<%
for each x in Session.Contents
  Response.Write(x & "=" & Session.Contents(x) & "<br />")
next
%>

hoặc:

<%
For i=1 to Session.Contents.Count
  Response.Write(i & "=" & Session.Contents(i) & "<br />")
Tiếp theo
%>

Ví dụ 3

<%
Session("name")="Hege"
Session("date")="2001/05/05"
for each x in Session.Contents
  Response.Write(x & "=" & Session.Contents(x) & "<br />")
next
%>

Kết quả xuất ra:

name=Hege
date=2001/05/05

Sách tham khảo đối tượng Application