Reputation: 7200
I want to be able to store variables that are accessible to all of the other files in my ASP.net project but can be modified programatically. What I am looking for is something akin to being able to pull information from the web.config file for say the database connection strings (ex System.Configuration.ConfigurationManager.ConnectionStrings["cnDatabase"].ToString())
I have variables that have values that are shared amongst all of the other pages and I would like to be able to modify in one location instead of having to update the same value in 4+ aspx.cs pages.
Upvotes: 0
Views: 488
Reputation: 36806
If you want something that is global to the application where you can add custom variables, use a Global.asax. Anything you add here will be available through the Global variable inherited in all pages and controls. If all you need is a key/value store, you can use the Application or Session static variables that are inherited in all pages and controls. Application (which is just a static instance of HttpApplicationState) is an object that you can use as a Hashtable to store custom values that will be available on all pages for all users. And, Session (HttpSessionState) is available the same way for use as a Hashtable, but the values you store will be unique per user session.
Note: if you need to access any of these objects outside of a page or control (ie. a custom class used within the context of a page request), you can get a reference to them through the current http context (HttpContext.Current).
Upvotes: 1
Reputation: 3994
AppSettings in the Web.Config file
or
public/internal constants
Upvotes: 2
Reputation: 116977
I think what you're looking for is the Settings feature of a project.
Here's a good introduction: http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx
Note: this isn't available for "Web Site" type projects, just ASP.Net Web Application projects.
Upvotes: 0