ASP Applications and Sessions

From the perspective of ASP, a web application is made up of all of the web pages contained in a virtual directory and its subdirectories. A session is a period of time during which a particular user is accessing pages in the application. A session begins when a user accesses a page in the application and ends when script on a page explicitly terminates the session or after a period of time has elapsed with no new page access. The default period of time is 20 minutes. The application is said to begin when the first session begins and to end when the last session ends.

Application and session startup and shutdown are ideal times to perform initialization and cleanup activities. For the application to be notified of these events, a file called global.asa must be in the application’s root folder, and in this file must be script to handle these events. Example 11-3 shows a skeleton global.asa file.

Example 11-3. Skeleton global.asa File

<script language="VBScript" runat="Server"> 

Sub Application_OnStart
   ' Application-wide initialization goes here.
End Sub

Sub Application_OnEnd
   ' Application-wide cleanup goes here.
End Sub

Sub Session_OnStart
   ' Per-session initialization goes here.
End Sub

Sub Session_OnEnd
   ' Per-session cleanup goes here.
End Sub

</script>

Note the use of the <SCRIPT> tag to identify the enclosed text as VBScript that is to be run by the server. VBScript is the default scripting language in IIS unless an administrator changes this ...

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.