Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to define global variables?
Message
From
10/11/2003 14:59:41
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00848129
Message ID:
00848455
Views:
13
>You can define static (shared) variables on the Global object (global.asax) and they are visible throughout the Web application. In fact you can create a custom class and define statics on it as well and they will also be globally accessible (assuming the namespace is visible).
>
>I do this all the time. I create an App class which underneath it has static sub objects such as Configuration, State etc. which are then accessible as:
>
>App.Configuration.ConnectionString
>
>Note however that you must lock access to these properties as they are not thread safe. So you might need to use:
>
>lock(App.Configuration)
>{
> App.Configuration.ConnectionString = "somenew value";
>}
>
>if there is a chance that the value is updated from multiple locations.
>
>I prefer this mechanism over the others because it gives you a stronly typed reference to the property which means you get Intellisense, compiler safety and to read at least you can simply retrieve the value wihtout having to check for nulls and un-boxing from Object type.
>
>
>Other than that you can use either the Cache object or the Application object to access variables throughout the application.

Thanks, yesterday I tried similar approach by creating a property by the use of Get and Set in my class level. But, at that level, I cannot specific a default value and I was not able to figure out how to make this accessible from any of the aspx pages.

So far, I did it as suggested earlier on this morning by the use of the Web.config file.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform