WebConfigurationManager.AppSettings Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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; }
static member AppSettings : System.Collections.Specialized.NameValueCollection
Public Shared ReadOnly Property AppSettings As NameValueCollection
Property Value
A NameValueCollection object that contains the AppSettingsSection object for the current Web application's default configuration.
Exceptions
A valid NameValueCollection object could not be retrieved with the application settings data.
Examples
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
Remarks
An AppSettingsSection object contains the configuration file's <appSettings>
section.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기