Global.asa: To be or not to be?

Submitted on: 1/5/2015 2:06:00 PM
By: Kaustav Acharya (from psc cd)  
Level: Beginner
User Rating: By 15 Users
Compatibility: ASP (Active Server Pages), HTML
Views: 2099
     To educate all coders when or when not to use the 'Global.asa' file and the conditions you must fullfill when you do use it. I knew I had a lot of trouble finding documentation like this. If you like it, please feel free to vote for it. Let me know what I can do to improve myself too, cuz this is my very first tutorial that I wrote. I've been told I'm good at explaining, but let me know ok? :) I'll see if I can dig up any more info on the 'Global.asa' file and try to continue this lesson. The most important reason why I created this tutorial is because most advanced scripts(i.e like my chat script, some database scripts, etc) use it. Very important piece of knowledge to be able to have at your fingertips. Now you can even impress your date with this stuff! ^_^ Not!! Hehe.


Did you use web based email accounts, shopping bags or online auctions before? If you did , didn't you ask your self how that web application recognize that this is me when I go from one page to another inside the site, or how it recognizes what I'm doing and its me who did that event and not another visitor to the site? How could the site remember visitors and know if they are still connected or not, or what are they doing?

If they are using IIS the answer probably lies within the Global.asa, Global.asa is an optional file that can be used to handle application and session events. For example with the Global.asa help you can do some function when a new user come to your site and another function when that user leaves the site. With the session object you can track users and their events and much more.

Some Facts about Global.asa :

The file must be named (Global.asa).
Global.asa must be stored in the root directory of the web application.
Global.asa is processed automatically by the server when
* The IIS starts and stops.
* Users start and stop sessions that use the application's web pages.
The scripts in the Global.asa are used to:
*Initialize application and session variables.
*Connect to databases.
*Send cookies.
In the Global.asa your script must be enclosed with the <SCRIPT> tag.
You can use any supported scripting language to write your scripts inside Global.asa
The IIS/PWS have a build in timelimit (defaulted to 20 minutes), so if the user don't request for any thing for that time limit the session will be ended automatically.

We use global.asa to make use of the application and session in the ASP, it can contain four scripts to handle application and session events.
Application_OnStart :run when IIS/PWS is started
Application_OnEnd :when IIS/PWS is ended
(Usually the application two scripts are run when the server is rebooted)

Session_OnStart :run when a user starts his/hers session
Session_OnEnd :when the session runs out
(two scripts that are run when a user starts his/hers session )

Things you must know about Global.asa:

Sessions will only work with visitors that have cookies enabled.
If you make a change to the script. Usually you have to reboot the server to get it refreshed and work correctly.

how Global.asa look from inside :

Sub Application_OnStart
'Your Application_OnStart code will be here
End Sub

Sub Application_OnEnd
'Your Application_OnEnd code will be here
End Sub

Sub Session_OnStart
'Your Session_OnStart code will be here
End Sub

Sub Session_OnEnd
'Your Session_OnEnd code will be here
End Sub

End of Tutorial

Other 4 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.