Working with ASP Applications
The Global.asa File
The Global.asa file stores the subroutines that are processed when an ASP application starts and ends. It is often used to declare variables and create objects such as database connections. The file is not required to run an application, but including it prevents you from having to include the same code on each page in your application. Code in the Global.asa file is not displayed, so the contents of the file should be limited to tasks required by the application to run. Note, too, that you cannot call subroutines contained in the Global.asa file from elsewhere in the application. You can create the file using a text editor. It should be given the file name Global.asa and saved in the root directory of the application. When an application starts, the server will look for and run this file first.
Working with Subroutines
All the code to be processed in the Global.asa file must be contained in one of four predefined subroutines: Application_OnStart, Application_OnEnd, Session_OnStart and Session_OnEnd. The Application_OnStart and Application_OnEnd subroutines let you perform tasks that will be processed when the application starts (for example, declaring variables) and ends (for example, removing variables). Similarly, the Session_OnStart and Session_OnEnd subroutines let you perform tasks to be processed at the start and end of sessions. You can, however, create your own subroutines, as long as they are called from within one of the four predefined subroutines. Subroutines should be enclosed in the
tags. The RUNAT attribute specifies that the script should be run on the server.
| // <