Global asa

As ASP Classic user, I have to have some post about global.asa
Here is one, imported from an old page

CodeFunctionName
What is this?

Public

Tested

Imported

Global.asa
The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application.
Note: The Global.asa file must be stored in the root directory of the ASP application, and each application can only have one Global.asa file.
The Global.asa file can contain only the following:
Application events
Session events
<object > declarations
TypeLibrary declarations
the #include directive
Application and Session Events

In Global.asa you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends. The code for this is placed in event handlers. Note: We do not use <% and % >, to insert scripts in the Global.asa file, we have to put the subroutines inside the HTML <script > tag:

<script language="vbscript" runat="server" >
sub Application_OnStart
' some code
end sub
sub Application_OnEnd
' some code
end sub
sub Session_OnStart
' some code
end sub
sub Session_OnEnd
' some code
end sub
</script >

Application Object
An application on the Web may be a group of ASP files. The ASP files work together to perform some purpose. The Application object in ASP is used to tie these files together.
The Application object is used to store and access variables from any page, just like the Session object. The difference is that ALL users share one Application object, while with Sessions there is one Session object for EACH user.
The Application object should hold information that will be used by many pages in the application (like database connection information). This means that you can access the information from any page. It also means that you can change the information in one place and the changes will automatically be reflected on all pages.

--------------------------------------------------------------------------------
Store and Retrieve Application Variables
Application variables can be accessed and changed by any page in the application.
You can create Application variables in "Global.asa" like this:

<script language="vbscript" runat="server" >
Sub Application_OnStart
application("vartime")=""
application("users")=1
End Sub
</script >

In the example above we have created two Application variables: "vartime" and "users".
You can access the value of an Application variable like this:

There are
<%
Response.Write(Application("users"))
% >
active connections.

--------------------------------------------------------------------------------
Loop Through the Contents Collection
The Contents collection contains all application variables. You can loop through the Contents collection, to see what's stored in it:
<%
dim i
For Each i in Application.Contents
Response.Write(i & " <br / >")
Next
% >

If you do not know the number of items in the 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
% >

--------------------------------------------------------------------------------

Loop Through the StaticObjects Collection
You can loop through the StaticObjects collection, to see the values of all objects stored in the Application object:

<%
dim i
For Each i in Application.StaticObjects
Response.Write(i & " <br / >")
Next
% >


--------------------------------------------------------------------------------

Lock and Unlock
You can lock an application with the "Lock" method. When an application is locked, the users cannot 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
% >

Views 2,750

Downloads 1,008

CodeID
DB ID