Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



ASP Application Object Examples


You can store different types of variables:

Application("greeting") = "Welcome to My Web World"
Application("num") = 25

You must use the Set keyword when storing objects:

Set Application("Obj1") = Server.CreateObject("MyComponent")

You can use methods and properties on subsequent ASP pages by using the following:

Application("Obj1").MyObjMethod

As an alternative, you can extract a local copy of the object:

Set MyLocalObj1 = Application("Obj1")
MyLocalObj.MyObjMethod

The next example demonstrates using an application variable called NumVisits to store the number of times a particular page has been accessed. The Lock method is called to ensure that only the current client can access or alter NumVisits. Calling the Unlock method then enables other clients to access the application object.

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

The next three examples demonstrate storing and manipulating an array in the Application object. The Lock and Unlock methods are used to control access to the Application object.

Application.Lock
Application("StoredArray") = MyArray
Application.Unlock

To retrieve the array from the Application object and modify its elements:

LocalArray = Application("StoredArray")
LocalArray(0) = "Hello"
LocalArray(1) = "there"

Next you need to restore the array in the Application object. This overwrites the values in StoredArray with new values.

Application.Lock
Application("StoredArray") = LocalArray
Application.Unlock


ContentsPreviousNextIndex