WebConfigurationManager.AppSettings Свойство

Определение

Получает параметры веб-приложения.

public:
 static property System::Collections::Specialized::NameValueCollection ^ AppSettings { System::Collections::Specialized::NameValueCollection ^ get(); };
public static System.Collections.Specialized.NameValueCollection AppSettings { get; }
static member AppSettings : System.Collections.Specialized.NameValueCollection
Public Shared ReadOnly Property AppSettings As NameValueCollection

Значение свойства

Объект NameValueCollection, содержащий объект AppSettingsSection для текущей конфигурации по умолчанию веб-приложения.

Исключения

Верный объект NameValueCollection не может быть извлечен с данными настройки приложения.

Примеры

В следующем примере показано, как получить доступ к сведениям о конфигурации с помощью AppSettings метода .


// Show the use of the AppSettings property
// to get the application settings. 
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();
}
' Show the use of AppSettings property
' to get the application settings.
Shared Sub GetAppSettings()
   
   ' Get the appSettings key,value pairs collection.
     Dim appSettings As NameValueCollection = _
     WebConfigurationManager.AppSettings
   
   ' Get the collection enumerator.
     Dim appSettingsEnum As IEnumerator = _
     appSettings.GetEnumerator()
   
   ' Loop through the collection and 
   ' display the appSettings key, value pairs.
   Dim i As Integer = 0
   Console.WriteLine("[Display appSettings]")
   While appSettingsEnum.MoveNext()
      Dim key As String = appSettings.AllKeys(i)
         Console.WriteLine("Key: {0} Value: {1}", _
         key, appSettings(key))
      i += 1
   End While
   
   Console.WriteLine()
End Sub

Комментарии

Объект AppSettingsSection содержит раздел файла конфигурации <appSettings> .

Применяется к

См. также раздел