In order to implement this class simply subclass the wwAppConfiguration class and add your own fields or properties to it. You can persist any simple properties and even most enums.

The best implementation of this class is to hang it off a static/shared property to allow it to be
reloaded when the app resets values. For example you can implement a class called App which has a static member Configuration. Use a static constructor to force the class to be loaded the first time the App member is accessed.

This allows the object to be accessible at all times. Also, since statics are always reloaded when Web apps are cycled and changes are made to web.config, the Static will cause any changes to web.config to be immediately detected and updated the first time the properties are accessed.

Here's the implementation of this setup:

// *** One way to implement a config class public class App { public static WebStoreConfig Configuration; static App() { /// *** Load the properties from the Config file Configuration = new WebStoreConfig(); Configuration.ReadKeysFromConfig(); } } public class WebStoreConfig : wwAppConfiguration { /// <summary> /// Determines how errors are displayed: /// 0 - Default Behavior (web.config settings) /// 1 - DebugMode off - Static Error Message /// 2 - DebugMode on - Request Error Display /// </summary> public int DebugMode = 0; /// <summary> /// The name of the store. Used in a few places as descriptions for headers etc. /// </summary> public string StoreName = "West Wind Web Store"; /// <summary> /// The name of the company. Used in some places on the site by default. /// </summary> public string CompanyName = "West Wind Technologies"; // ... etc. }

Once this class setup is done you can access this class from anywhere in the application with:

string CompanyName = App.Configuration.CompanyName; int DebugMode = App.Configuration.DebugMode;

If you accessing the class in ASP.Net pages you would need to use the fully qualified path unless you add a namespace reference. In the Web Store the class is referenced like this:

<%= Westwind.WebStore.App.Configuration.CompanyName %>

Since the App.Configuration member is static there's no need to create an instance of the class yourself.

If you don't want to use a new class in Web applications you can add the static Configuration member off the Global class in Global.asax(.cs). You can then use the same approach by referencing:

int DebugMode = Global.Configuration.DebugMode;

See also:

Class wwAppConfiguration

Last Updated: 4/21/2004 | Send topic feedback