Understanding the role of the Global.asa file - ASP basic tutorial
First of all, .asa is the file suffix, which is the abbreviation of Active Server Application. The Global.asa file can manage two very demanding objects in ASP applications: Application and Session.
It is actually an optional file in which program writers can specify event scripts and declare objects with session and application scope. The contents of this file are not used for display to the user, but are used to store event information and objects used globally by the application. This file must be placed in the root directory of the application. There can only be one Global.asa file per application.
The most common misconception about the Global.asa file is that it can be used as a library for commonly used functions and subroutines. The Global.asa file can only be used to create object references and capture starts, and to end Application objects and Session objects.
The Global.asa file is mainly accessed based on session-level events and is called in the following three situations:
1. When the Application_OnStart or Application_OnEnd event is triggered.
2. When the Session_OnStart or Session_OnEnd event is triggered.
3. When referencing an object (Object) instantiated in the Global.asa file.
The standard file format of Global.asa is as follows:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'Application_OnStart Runs when any customer first visits the home page of the application
End Sub
SubSession_OnStart
'Session_OnStart runs when the client first runs any page in the ASP application
End Sub
SubSession_OnEnd
'Session_OnEnd Runs when a client's session times out or exits the application
End Sub
Sub Application_OnEnd
'Application_OnEnd runs when the WEB server of the site is shut down
End Sub
</SCRIPT>