WebConfigurationManager.AppSettings 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得網站的應用程式設定。
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
屬性值
NameValueCollection 物件,包含目前 Web 應用程式預設組態的 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>
區段。