Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP Application object

ASP Application object


A group of ASP files that work together to accomplish a task is called an application.


Application object

An application on the Web can be a group of ASP files. These ASP files work together to accomplish a task. The Application object in ASP is used to bind these files together.

The Application object is used to store and access variables from any page, similar to the Session object. The difference is that all users share one Application object, whereas Session objects have a one-to-one relationship with users.

The Application object holds information that can be used by many pages in an application (such as database connection information). This information can be accessed from any page. You can also change it in one place, and those changes are automatically reflected on all pages.


Storing and retrieving Application variables

Application variables can be accessed and changed by any page in the application.

You can create Application variables in "Global.asa" as follows:

In the example above, we created two Application variables: "vartime" and "users".

You can access the value of an Application variable as follows:

There are

<%

Response.Write(Application("users"))

%>

active connections.


Iterating over the Contents collection

The Contents collection contains all the application variables. You can view the variables stored in it by iterating over the Contents collection:

<%

dim i

For Each i in Application.Contents

Response.Write(i & "
")

Next

%>

If you do not know the number of items in the Contents collection, you can use the Count property:

<%

dim i

dim j

j=Application.Contents.Count

For i=1 to j

Response.Write(Application.Contents(i) & "
")

Next

%>


Iterating over the StaticObjects collection

You can view the values of all objects stored in the Application object by iterating over the StaticObjects collection:

<%

dim i

For Each i in Application.StaticObjects

Response.Write(i & "
")

Next

%>


Locking and unlocking

You can use the "Lock" method to lock an application. When the application is locked, users cannot change Application variables (except the user who is accessing them). You can also use the "Unlock" method to unlock the application. This method removes the lock on the Application variables:

<%

Application.Lock

'do some application object operations

Application.Unlock

%>