Hi Nathan,
A file is code. It does not have anything to do with the program, other than
the fact that the code in it is compiled into one. The global.asax file is
all code. It will help if you understand this, as well as what it creates
when compiled, which is what you need to be concerned about.
The global.asax file is a code file that defines a class. This class is used
at run-time to fire events that occur during the lifetime of your app. The
name of the class is "global" - not "global.asax," as "global.asax" is a
file name. I hope I'm getting this across clearly. The class is used by the
ASP.Net worker process during its lifetime, that is, the lifetime of the
ASP.Net application, which lives from the moment the first Request to your
application occurs, until 20 minutes (default) after the last Request
occurs, or whenever the web server is restarted, or, on a Windows 2003
server, whenever the Application Pool for your ASP.net app is recycled.
It contains a number of event handlers, which are pre-wired by the ASP.Net
ISAPI, to be fired at certain times during the lifetime of your ASP.Net app.
Each of these event handlers is a method (a function, if you will). Any
variables declared inside a method are scoped locally to that method. That
is, they do not exist when the method exits, just as they would in any other
class method.
I'm just trying to give you some background here, so that you will
understand better, and hopefully not encounter this situation again in some
different form.
So, as to the answer, let's start by forgetting that these variables and
functions are declared in the global.asax file. They are members of a class.
Yes, the class is named "global" but that doesn't mean that everything in it
IS global. However, these event handers give you an opportunity to CREATE
some global variables. The global class has access to the Application Cache,
which lives for the entire lifetime of your application, and is, in fact,
accessible to all pages and classes used in your application. In addition,
several event handlers in the global class have access to user-specific
"global" cache, that is Session state. If you want to persist something in
state that is accessible only to one user client, and only for the time for
which that user client is connected, store it there.
Of course there are other state mechanisms that have nothing to do with the
global class, or global event handlers, such as ViewState, which is
Page-specific.
--
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
Post by Nathan SokalskiI would like to access variables and functions that I declare in the
Global.asax.vb file. However, I am having trouble doing that. What does the
declaration have to look like in the Global.asax.vb file, and what would I
do to access it? (I am using VB.NET for my code) Thanks.
--
Nathan Sokalski
http://www.nathansokalski.com/