Latest web development tutorials

ASP Contents collection

Application Object Reference Complete Application Object Reference

Contents collection contains a script to add commands to the application / session for all projects.

Tip: To remove an item from the Contents collection, use the Remove method and RemoveAll.

grammar

Application.Contents(Key)

Session.Contents(Key)

参数 描述
key 必需。要取回的项目的名称。


For instance Application Object

Example 1

Please note, name and objtest will be appended to the Contents collection:

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

Example 2

Contents collection traversal:

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

或者:

<%
For i=1 to Application.Contents.Count
Response.Write(i & "=" & Application.Contents(i) & "<br>")
Next
%>

Example 3

<%
Application("date")="2001/05/05"
Application("author")="W3CSchool"

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

输出:

date=2001/05/05
author=W3CSchool


For instance Session object

Example 1

Please note, name and objtest will be appended to the Contents collection:

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

Example 2

Contents collection traversal:

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

或者:

<%
For i=1 to Session.Contents.Count
Response.Write(i & "=" & Session.Contents(i) & "<br>")
Next
%>

Example 3

<%
Session("name")="Hege"
Session("date")="2001/05/05"

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

输出:

name=Hege
date=2001/05/05


Application Object Reference Complete Application Object Reference