Riferimento a .NET Framework
Proprietà WebConfigurationManager..::.AppSettings

Aggiornamento: novembre 2007

Ottiene i dati dell'oggetto AppSettingsSection per la configurazione predefinita dell'applicazione Web corrente.

Spazio dei nomi:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

Sintassi

Visual Basic - (Dichiarazione)
Public Shared ReadOnly Property AppSettings As NameValueCollection
Visual Basic (Utilizzo)
Dim value As NameValueCollection

value = WebConfigurationManager.AppSettings
C#
public static NameValueCollection AppSettings { get; }
Visual C++
public:
static property NameValueCollection^ AppSettings {
    NameValueCollection^ get ();
}
J#
/** @property */
public static NameValueCollection get_AppSettings()
JScript
public static function get AppSettings () : NameValueCollection

Valore proprietà

Tipo: System.Collections.Specialized..::.NameValueCollection

Oggetto NameValueCollection contenente l'oggetto AppSettingsSection per la configurazione predefinita dell'applicazione Web corrente.

Eccezioni

EccezioneCondizione
ConfigurationErrorsException

Impossibile recuperare un oggetto NameValueCollection valido con i dati di impostazione dell'applicazione.

Note

Oggetto AppSettingsSection contenente la sezione <appSettings> del file di configurazione.

Esempi

Nell'esempio riportato di seguito viene illustrato come accedere alle informazioni sulla configurazione con il metodo AppSettings.

Visual Basic
' Show the use of AppSettings. 
' It gets the section from the configuration 
' file located at the application current level. 
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 'GetAppSettings


C#
// 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();
}

Piattaforme

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

.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

Informazioni sulla versione

.NET Framework

Supportato in: 3.5, 3.0, 2.0
Vedere anche

Riferimenti

Altre risorse

Tag :


Page view tracker