Using Global.asa
page 2 of 4
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27051/ 40

Creating the file

Creating Global.asa

To create the Global.asa, just use notepad to create a file called Global.asa in your virtual directory or root directory. Then we can get coding.

The Global.asa have 4 main sections -

  • Application_onStart() - is executed whenever an application begins.

  • Application_onEnd() - is executed whenever an application stops.

  • Session_onStart() - executed whenever a session beings.

  • Session_onEnd() - its amazing how this one is executed when a session...... ENDS!

Lets actually create a Global.asa now.

<script language="VBScript" RUNAT="SERVER">

Sub Application_OnStart()
Set objConn = CreateObject("ADODB.Connection")
Set Application("objConn") = objConn
Set Application("stTime") = CStr(Now)
End Sub

Sub Application_OnEnd()
Set Application("objConn") = Nothing
Set objConn = Nothing

End Sub

Sub Session_OnStart()
Application.Lock
Application("visitors") = Application("visitors") + 1
Session("visitor") = Application("visitors")
Application.Unlock
End Sub

Sub Session_OnEnd()

End Sub

</script>

This seems pretty straight forward -

  • When the Application Starts - An ADODB.Connection object is created and made an application variable of the same name. The current time is stored as a string as well, in an application variable.
  • When the Application Ends - The connection object gets set to nothing.
  • When a Session Starts - We increment the visitor counter by 1 and set that value to the application variable and the session variable. We use Application.Lock and Unlock to make sure that no-one else updates the value at the same time (things could get messy).
  • When the Session Ends - Nothing happens.

You can see that this can be used for some things that you may do already, and things that you might find useful. Things to keep note of - The <script> tags and the RUNAT="SERVER" property. Also, the language doesn't have to be VBScript.


View Entire Article

User Comments

Title: exceeeeeeeeeeeeelent   
Name: jiji
Date: 2005-03-09 9:32:41 AM
Comment:
this was the best explanation of for some one who is a beginner and was very helpfull
thank you for saving our neck
Title: Global.asa   
Name: P.Prathiba
Date: 2005-02-19 1:02:16 AM
Comment:
This information is very useful for me.
Title: Well Done   
Name: Rizwan
Date: 2005-01-15 4:40:40 AM
Comment:
Great Help from your site.

Keep it up! This type of help are very useful for newbies and sometimes for lazy professionals. lol...
Thanks Mr. Author!
Title: Global   
Name: Raj
Date: 2005-01-12 10:28:21 AM
Comment:
This information is quiet useful.
Title: New User   
Name: Mollie...
Date: 2004-10-27 10:48:09 PM
Comment:
Thanks! Your Article helped me out....
Title: Global ASA   
Name: Tonya
Date: 2004-10-24 11:36:05 AM
Comment:
This information is GREAT. Expecially your picture on Virtural and Non-Vertual directories. I have created a small application, created a Global ASA to set a variable to current date. I then created an asp page which will display text along with the date. When I run the page in the browser, it displays my text but not the date. My question is, do I need to turn something on in order for a Global asa to execute?

Thanks for your help.
Title: hi jaan   
Name: Mehr
Date: 2004-09-12 3:42:13 AM
Comment:
i like it this way...keep going...:p
Title: Global.asa   
Name: Niranjan
Date: 2004-08-30 6:16:07 AM
Comment:
THis is very usefull artickle.I was confused with this becuse i was developing the web site without using this.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 9:09:08 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search