![]() |
![]() |
|||||||
|
Lock |
Prevents script from modifying object properties |
Unlock |
Enables script to modify object properties after execution of the Lock method. |
Events
Application_OnStart |
Runs when an ASP page belonging to the application is accessed for the first time. |
Application_OnEnd |
Runs when the Web server is shut down. |
Set Application("var1") = Session
Set Application("var2") = Request
Set Application("var3") = Response
Set Application("var4") = Server
Set Application("var5") = Application
Before you store an object in the Application object, you must know what threading model it uses. Only objects marked as both free and apartment-threaded can be stored in the Application object.Application("StoredArray") (3) = "new value"
Instead of storing the value "new value" in StoredArray(3) the value is stored in the Application collection, overwriting any information stored at Application(3).Note:
It is strongly recommended that if you store an array in the Application object that you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done making changes to the array, store the array back into the Application object to save changes. This is demonstrated in the following examples.
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 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
Copyright © 2000 Chili!Soft