[Lifetime of variables][Applications][The Global.asa file][ASP Built-in Objects][Response Object]
[Request Objects][Content Linking]

Applications

The Application Object is used to tie together Web pages into an application. The Application Object stores variables and objects for the entire application. Any page that is a part of this application can access these variables and objects. There is one instance of the Application Object for each application running on the server, but many clients can access the same application.

Store and Retrieve Variables' Values

Application variables and objects must be created in the Global.asa file, but they can be accessed and changed by any page in the application.

You can store variables in the Application Object (in global.asa), like this:

<script language="vbscript" runat="server">

Sub Application_OnStart

application("vartime")=""

application("whoon")=1

End Sub

</script>

You can get variable values from the Application Object, like this:

There are

<%Response.Write(Application("whoon"))%>

active connections.

Looping Through the Contents

You can loop through the "Contents" collection, to see the values of all the variables stored in the Application Object:

<%

dim i

For Each i in Application.Contents

Response.Write(Application.Contents(i) & "<br>")

Next

%>

Result:

1

If you don't know how many items are stored in a "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) & "<br>")

Next

%>

Result:

1

Looping Through the Objects

You can loop through the "StaticObjects" collection, to see the values of all the objects stored in the Application Object:

<%

dim I

For Each i in Application.StaticObjects

Response.Write(Application.StaticObjects(i) & "<br>")

Next

%>

Lock and Unlock

You can lock an application with the "Lock" method. When an application is locked, the users can not change the Application variables (other than the one currently accessing it). You can unlock an application with the "Unlock" method. This method removes the lock from the Application variable:

<%

Application.Lock

'do some application object operations

Application.Unlock

%>