In order to work properly, they must be placed inside a virtual application on the server, and the provided global.asa files are placed in the root directory of the application. The easiest way to do this is to place the Global.asa file in the root directory of the default Web site (c:/inetpub/wwwroot by default).
Renaming any existing Global.asa file is a good way to recover the file later.
1. Display the contents of the Application collection
The Aspcounter object is a member of the StaticObjects collection (defined by the element), but the remainder (instantiated by Server.CreateObject) is a member of the contents collection.
You can see the values that you put into these collections using the Global.asa example page, which you've seen earlier:
!--Declare instance of the Aspcounter component with
Application-level Scope//-->
Progid= "MSWC. Counters ">
...
...
(1) Traversing the code of the Contents collection
To traverse the Contents collection, you can use a For each ... Next structure. Each item in the collection can be a simple variant type variable, a Variant array, or a reference to an object. Because each type of value needs to be handled differently, you have to check each one to determine its type.
You can use the VarType function in VBScript to do this work. Here you use the IsObject and IsArray functions instead:
For each objitem in application.contents
If IsObject (application.contents (objitem)) Then
Response.Write "Object Reference: '" & objitem & "'
”
ElseIf IsArray (application.contents (objitem)) Then
Response.Write "Array:" "& objitem &" ' contents are:
”
Vararray = application.contents (objitem)
' note:the following with a one-dimensional array
For intloop = 0 to UBound (vararray)
Response.Write "Index (" & intloop & ") =" & _
Vararray (intloop) & "
”
Next
Else
Response.Write "Variable:" "& objitem &" ' = "_
& Application.Contents (objitem) & "
”
End If
Next
Notice how the program retrieves the array from the Application object. Assign it to a local (Variant) variable, using the following statement:
Vararray = application.contents (objitem)
You can use the UBound function to find the size of the array (the number of elements), which can be used as a termination condition for traversal:
For intloop = 0 UBound (vararray)
This example is a one-dimensional array and will only display the contents of such an array. You can edit your code to handle multidimensional arrays as needed, for example:
For intloop = 0 to UBound (vararray)
Intnumberofdimensions = UBound (Vararray, 1)
For intdimension = 0 to Intnumberofdimensions
Response.Write "Index (" & intloop & ") =" _
& Vararray (Intloop, intdimension)
Next
Response.Write ""
Next
(2) Traversing the code of the StaticObjects collection
The StaticObjects collection contains all the object references that are declared using the element in Global.asa. Because each entry is an object variable, the array can be traversed by simple code. We will output the name of the object (as defined in the id attribute):
For each objitem in application.staticobjects
If IsObject (Application.staticobjects (objitem)) Then
Response.Write " element:id= '" & Objitem & "'
”
End If
Next