Home arrow ASP arrow Page 3 - Maintaining Session State With ASP

Maintaining Session State With ASP

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.

Author Info:
By: Himanshu Khatri
Rating: 5 stars5 stars5 stars5 stars5 stars / 82
August 30, 2002
  1. · Maintaining Session State With ASP
  2. · The Session Object
  3. · The Application Object
  4. · The Global.asa File
  5. · Conclusion

print this article

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.



  • Lock: Prevents other users from changing the application objects properties
  • Unlock: Allows other users to change the application objects properties
  • 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.


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


The following VBScript will display the uptime:

<% @ language="vbscript" %>
<% Option Explicit %>

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
days = Day(runTime)
End If
hours = Hour(runTime)
minutes = Minute(runTime)
seconds = Second(runTime)

' Display the uptime
Response.Write "Uptime: " & days & " days(s), "
Response.Write hours & " hour(s), "
Response.Write minutes & " minute(s), and "
Response.Write seconds & " second(s)"


blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials