Application Object

You can use the Application object to share information among all users of a given application. An ASP-based application is defined as all the .asp files in a virtual directory and its subdirectories. Because the Application object can be shared by more than one user, there are Lock and Unlock methods to ensure that multiple users do not try to alter a property simultaneously.

Syntax

Application.method

Methods

Lock

The Lock method prevents other clients from modifying Application object properties.

Unlock

The Unlock method allows other clients to modify Application object properties.

Events

Application_OnEnd

Application_OnStart

Scripts for the preceding events are declared in the Global file. For more information about these events and the Global file, see the Global File Reference.

Remarks

You can store values in the Application object by using the following script.

<% 
   Application("greeting") = "Welcome to My Web World!"
   Application("num") = 25
%>
 

However, if you store an object in the Application object, you must use the following script. (Note the use of the Set keyword in the second line.)

<% 
Set MyObj = Server.CreateObject("MyComponent")
Set Application("Obj1") = MyObj
%>
 

You can then reference the methods and properties of MyObj on subsequent Web pages, by using the following:

<% Application("Obj1").MyObjMethod %>
 

Note You can also create objects with application scope by using the <OBJECT> tag in the Global file. For more information, see the Global File Reference.

You cannot store a built-in object in the Application object. For example, each of the following lines would return an error.

<%
Set Application("var1") = Session
Set Application("var2") = Request
Set Application("var3") = Response
Set Application("var4") = Server
Set Application("var5") = Application
%>
 

Example

<% 
Application.Lock
Application("NumVisits") = Application("NumVisits") + 1
Application.Unlock
%> This application page has been visited <%= Application("NumVisits") %> times!

The preceding example uses the application variable NumVisits to store the number of times that a particular page has been accessed. In the preceding example, the Lock method is called to ensure that only the current client can access or alter NumVisits. Calling the Unlock method then enables other users to access the Application object.