global declaration of variables

Hi all,

As i'm new to asp.net,kindly help me in the following problem.
I want to declare a global variable to make use of it in mutliple webforms.
Currently i declared in global.asax file at Sub Session_Start.
Is this the standard way of declaring a global variable.
Please advice.
Thanks in advance,
ragyari.
0
ragyari
12/8/2004 10:14:07 AM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 3 Replies
👁️‍🗨️ 452 Views


Hello,

Unique to the user? Use a session variable.
Brian

Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
0
bmains
12/8/2004 12:34:20 PM
Right, or a truly global var would be used at Application scope, so use an Application var.

In this world there are 10 types of people, those that know binary and those who don't.
0
optik
12/8/2004 1:12:47 PM
Session items are specific to a particular user and span pages.

Session(yourKey) = someObject
Application items are shared by all users
Application(yourKey) = someObject
Cache items are also shared by all users but give you flexibility in expiring each item.
Cache.Add(...)
If you using VB.NET and are looking for an Application scoped variable, then you should use a public variable declared in a Module outside of any Class. According to the MS docs, this is faster than using an Application item.

When using application scoped variables, always stay conscious of threading issues.
i.e. two users updating the var at the same time...

Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
12/8/2004 1:31:28 PM
Reply: