By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,549 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,549 IT Pros & Developers. It's quick & easy.

Accessing variables declared in Global.asax.vb

P: n/a
I 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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Global.asax is a class that is always called before your page is loaded, but
it's not part of of your page really. (Master page in asp.net 2.0 will be
more what you are looking for)

The only thing I know you can access from global.asax are Public Shared
(Static in c#) functions or variables.

Using shared variable must be considered very dangerous because they are
often source of non-thread safe result. If you want to carry information
between page, better look into Session variable.

Hope that help you,

-----------------------
Jean-Claude Morin, MCAD
Software Developer
2k1Soft/kCentric, Canada
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:ee****************@TK2MSFTNGP10.phx.gbl...
I 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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2

P: n/a
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.

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:ee****************@TK2MSFTNGP10.phx.gbl...
I 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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.