When working with ASP pages,
you've probably used the session object to store variables that you want to
use throughout your website. But what if you want to store the same variables
forever, like connection strings or objects that you use over and over? What
if you want to store variables when a session begins so you can store things
like the time that user logged on? You can now do this (well, you always could
actually) with Global.asa. This article will teach you about what Global.asa
is, what to use it for and what not to use it for.
What is it?
Before I tell you, I must get some
terms clear -
Application - An
application (in ASP terms) is basically your asp site. Usually this is a
virtual directory or maybe the whole thing. An application starts when the web
server starts and ends when the web server stops. Which means that whatever
variable you put in to start when the application starts (we'll cover that
soon) won't stop till it stops.
Session - A session is from
the time that a user starts looking at your site to the time he/she stops.
Session is kept track of by a cookie on the user that gets deleted when the
user closes his/her browser. All session data is stored on the server.
Now that we've got that out of the
Global.asa is a file that goes in
the root directory of your site (or virtual directory) and whenever your
application is started or stopped or whenever a user comes onto your site or
leaves your site it gets activated. That is a pretty ugly description of it
but that's it. The main purpose of it is to store information in Application
variables and Session variables when the program is started.
If you didn't use Global.asa and
wanted to store Application variables, then you would need to have created a
file that created them and run that file when the app started and run it again
if it restarted, the same with session variables. You generally don't know
where a user comes into your site and if you want to assign session variables
then you would have to create the same code on every page to check and create
those variables. Global.asa eliminates this. When a user logs onto your site,
wherever he/she is they get the variables automatically, whenever the
application is started the variables are assigned automatically.