ASP utilizes a file, global.asa, to specify application startup and shutdown procedures and to make available global variables. Global.asa handles these resources at both the application and session levels, and provides control over four events: Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd. To fully understand how global.asa should be utilized, some background information will clear up some of the more confusing aspects.
First off, an application is a set of ASP pages and scripts that make up the content of a website, and a session is a single usage of that site. The event handler Application_OnStart runs whenever the website starts up, and Application_OnEnd runs when the website shuts down. The remaining event handlers, Session_OnStart and Session_OnEnd runs each time a user starts a session of the application.
When a user visits a website, the web server opens a session for that specific user. The session reserves a part of the web server's memory to store certain variables and user states. By default, the session remains active until after 20 minutes from the last user interaction, not immediately after the user leaves the site or even closes the web browser.
Session("Username") = "Patrick"
Global.asa should sit at the root directory of the application site. The ASP server will first look for global.asa in the same directory as the ASP file. If the file does not exist there, the server traverses up through the directory tree until it either locates global.asa or reaches the root. The very nature of a global file suggests that just one global.asa should exist, and that it sit at the root.
<script language=VBScript RUNAT=Server> Sub Application_OnStart 'Add your Application_OnStart code here End Sub </script> <script language=VBScript runat=Server> Sub Application_OnEnd 'Add your Application_OnEnd code here End Sub </script> <script language=VBScript runat=Server> Sub Session_OnStart 'Add your Session_OnStart code here End Sub </script> <script language=VBScript runat=Server> Sub Session_OnEnd 'Add your Session_OnEnd code here End Sub </script> |