global variables

  • Thread starter Thread starter Tina
  • Start date Start date
T

Tina

I would like to know the preferred way in which to define, store, and
retrieve global varialbes in asp.net applications. I have read through past
threads here and have seen mixed advice. Some say to define them in
global.asax but I can't seem to reference them. Others say that they must
be defined in the session_start and that they cannot be simply defined in
global.asax. Yet others say just put them in any class anywhere and
reference them.

It seems the right answer would be defining them as session variables but I
can't seem to reference them with session.myvariable
Thanks,
T
 
If you want the same variable across the application, you use Application
variables and create them in the application_start event. If you need them
individually for each session then you use session variables. You don't
reference them assession.myvariable, it is actually a collection so you
would reference them (in C#) as session["myvariable"]. Just remember that
these are kept in server memory so if you have lots of sessions this can be
a performance drag.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Back
Top