WebConfigurationManager.AppSettings WebConfigurationManager.AppSettings WebConfigurationManager.AppSettings WebConfigurationManager.AppSettings Property

Definizione

Ottiene le impostazioni dell'applicazione del sito Web.Gets the Web site's application settings.

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

Valore della proprietà

Oggetto NameValueCollection contenente l'oggetto AppSettingsSection per la configurazione predefinita dell'applicazione Web corrente.A NameValueCollection object that contains the AppSettingsSection object for the current Web application's default configuration.

Eccezioni

Impossibile recuperare un oggetto NameValueCollection valido con i dati di impostazione dell'applicazione.A valid NameValueCollection object could not be retrieved with the application settings data.

Esempi

Nell'esempio seguente viene illustrato come accedere alle informazioni di configurazione AppSettings con il metodo.The following example shows how to access configuration information with the AppSettings method.



// 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


Commenti

Un AppSettingsSection oggetto contiene la sezione del file <appSettings> di configurazione.An AppSettingsSection object contains the configuration file's <appSettings> section.

Si applica a

Vedi anche