Declaring variables with global scope (Newbie Question)!

  • Thread starter Thread starter Mortal Wombat
  • Start date Start date
M

Mortal Wombat

Hi,

I am a beginner VB.NET developer and am trying to create my first ASP.NET
web application. I know that in a standard Windows Form type application, if
I want to declare a particular variable as global, then I declare it in a
separate module... any variables then declared in that module will be
available to any form within the application. How can I achieve the same
thing in an ASP.NET application?
I wish to declare a few variables that have scope beyond one WebForm page,
so that I can use the variable in other WebForm pages within the
application.

I suspect it is something to do with the global.asax file, but I cannot find
a reference for the correct way to do it.

Many thanks in advance,

MW
 
"Global" is a kind of different concept in ASP.Net than in Windows Forms. In
a Windows Form, all of the components of the form reside in the same
persistent memory space on the same machine. In ASP.Net, you're talking
about a client-server app with memory space on the client, and separate
memory spaces on the server for each client (Session State), as well as
memory space for the entire server application (Application State), and
other places as well where you can cache things with varying kinds of scope.

If you're talking strictly about the server component of the app, you can
store data which is global to the entire app in Application State, or in
static objects in your heap, as well as in storage media, such as files and
database. If you want to store data that is global to a single client
Session, but across all pages, you can store it in Session State, or in
Cookies, which actually reside on the Client, but are transmitted to the
server with each Request.

The global.asax class contains a number of event handlers which you can use
to store such data at the beginning of the Application LifeCycle, at the
beginning of a user Session, and others.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
John makes a good point. When deciding on the scope af any variable, it
should be as small as necessary, in order to avoid any possible conflicts.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
Thanks for all your responses, I will investigate everything you mentioned
to see which option I should use.
Thanks!

MW
 
Back
Top