CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, September 25, 2006

Creating AppSettings class in .NET

Description: Stores AppSettings from web.config in an easy to access class.
static AppSettings()
    {
        // static constructor - load settings from Web.config
        MyAppSetting = GetAppSetting("my_app_setting");
    }

    public static readonly string
        MyAppSetting;

    public static string GetAppSetting(string key)
    {
        return System.Configuration.ConfigurationManager.AppSettings[key];
    }
}

Post a Comment