Sessions and cookies can be used to persist visitor information. In this article Himanshu shows us how to main session state with ASP using a combination of cookies, sessions and the global.asa file.
Maintaining Session State With ASP - The Application Object (Page 3 of 5 )
The Application object is used to store variables and to access variables from any page. All users share one Application object.
All variables created within the application object have application level scope, meaning that they are accessible to all users who visit your site. All ASP pages in a virtual directory and its subdirectories come under the application scope, so more than one user shares application level variables at any time.
Syntax:
Application.method
Methods:
Lock: Prevents other users from changing the application objects properties
Unlock: Allows other users to change the application objects properties
Events:
Application_OnEnd: This routine is called when all user sessions expire and the application quits. This event lives in the global.asa file, which we will look at shortly.
Application_OnStart: This routine is called when the application object is first references. This event lives in the global.asa file as well.
Example:
This example uses an application variable to determine the uptime of the server. To achieve this we simply add an application variable to the OnStart event in the global.asa file, which needs to exist in the root directory of your web server:
<script language="VBScript" runat="Server">
Sub Application_OnStart Application("startTime") = Now End Sub
Dim days, hours, minutes, seconds, startTime, runTime
' Read the start time from the ' Application variable startTime = CDate(Application("startTime"))
' Take the difference runTime = CDate(Now - startTime)
' Calculate the time components If DateDiff("d", startTime, Now) = 0 Then days = 0 Else days = Day(runTime) End If hours = Hour(runTime) minutes = Minute(runTime) seconds = Second(runTime)