WebConfigurationManager.AppSettings Property

Gets the AppSettingsSection data for the current Web application's default configuration.

Namespace: System.Web.Configuration
Assembly: System.Web (in system.web.dll)

public static NameValueCollection AppSettings { get; }
/** @property */
public static NameValueCollection get_AppSettings ()

public static function get AppSettings () : NameValueCollection

Not applicable.

Property Value

A NameValueCollection object that contains the AppSettingsSection object for the current Web application's default configuration.

Exception typeCondition

ConfigurationErrorsException

A valid NameValueCollection object could not be retrieved with the application settings data.

An AppSettingsSection object contains the configuration file's <appSettings> section.

The following example shows how to access configuration information with the AppSettings method.


// Show the use of AppSettings. 
// It gets the section from the configuration 
// file located at the application current level. 
static void GetAppSettings()
{

    // Get the appSettings key,value pairs collection.
    NameValueCollection appSettings =
        WebConfigurationManager.AppSettings
        as NameValueCollection;

    // Get the collection enumerator.
    IEnumerator appSettingsEnum =
        appSettings.GetEnumerator();

    // Loop through the collection and 
    // display the appSettings key, value pairs.
    int i = 0;
    Console.WriteLine("[Display appSettings]");
    while (appSettingsEnum.MoveNext())
    {
        string key = appSettings.AllKeys[i].ToString();
        Console.WriteLine("Key: {0} Value: {1}",
        key, appSettings[key]);
        i += 1;
    }

    Console.WriteLine();
}


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: