WebConfigurationManager.AppSettings Property

 

Gets the Web site's application settings.

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

Public Shared ReadOnly Property AppSettings As NameValueCollection

Property Value

Type: System.Collections.Specialized.NameValueCollection

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

Exception Condition
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 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 'GetAppSettings


.NET Framework
Available since 2.0
Return to top
Show: