ProviderSettings 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示與提供者關聯的組態項目。
public ref class ProviderSettings sealed : System::Configuration::ConfigurationElement
public sealed class ProviderSettings : System.Configuration.ConfigurationElement
type ProviderSettings = class
inherit ConfigurationElement
Public NotInheritable Class ProviderSettings
Inherits ConfigurationElement
- 繼承
範例
下列程式代碼範例示範如何使用 ProviderSettings。
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Configuration;
using System.Security.Permissions;
namespace Samples.AspNet
{
// Shows how to use the ProviderSettings.
public class UsingProviderSettings
{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
private static void GetProviderSettings()
{
// Get the application configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
ProtectedConfigurationSection pSection =
config.GetSection("configProtectedData")
as ProtectedConfigurationSection;
ProviderSettingsCollection providerSettings =
pSection.Providers;
foreach (ProviderSettings pSettings in
providerSettings)
{
Console.WriteLine(
"Provider settings name: {0}",
pSettings.Name);
Console.WriteLine(
"Provider settings type: {0}",
pSettings.Type);
NameValueCollection parameters =
pSettings.Parameters;
IEnumerator pEnum =
parameters.GetEnumerator();
int i = 0;
while (pEnum.MoveNext())
{
string pLength =
parameters[i].Length.ToString();
Console.WriteLine(
"Provider ssettings: {0} has {1} parameters",
pSettings.Name, pLength);
}
}
}
static void Main(string[] args)
{
GetProviderSettings();
}
}
}
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Text
Imports System.Configuration
Imports System.Security.Permissions
' Shows how to use the ProviderSettings.
Namespace Samples.AspNet
Public Class UsingProviderSettings
<PermissionSet( _
SecurityAction.Demand, Name:="FullTrust")> _
Private Shared Sub GetProviderSettings()
' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim pSection As _
ProtectedConfigurationSection = _
config.GetSection("configProtectedData")
Dim providerSettings _
As ProviderSettingsCollection = _
pSection.Providers
Dim pSettings As ProviderSettings
For Each pSettings In providerSettings
Console.WriteLine( _
"Provider settings name: {0}", _
pSettings.Name)
Console.WriteLine( _
"Provider settings type: {0}", _
pSettings.Type)
Dim parameters _
As NameValueCollection = pSettings.Parameters
Dim pEnum _
As IEnumerator = parameters.GetEnumerator()
Dim i As Integer = 0
While pEnum.MoveNext()
Dim pLength As String = _
parameters(i).Length.ToString()
Console.WriteLine( _
"Provider ssettings: {0} has {1} parameters", _
pSettings.Name, pLength)
End While
Next pSettings
End Sub
Public Shared Sub Main(ByVal args() As String)
GetProviderSettings()
End Sub
End Class
End Namespace
以下是上述範例所使用的組態檔摘錄。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configProtectedData>
<providers>
<clear />
<add
name="TripleDESProtectedConfigurationProvider"
type="Samples.Aspnet.TripleDESProtectedConfigurationProvider, protectedconfigurationproviderlib, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=79e01ae0f5cfc66f, processorArchitecture=MSIL" />
</providers>
</configProtectedData>
</configuration>
備註
ASP.NET 會使用提供者來執行功能所需的特定服務。 例如,成員資格功能會使用提供者來協調資料庫中成員資格數據的持續性。
在組態檔中,個別提供者會新增至 providers
特定功能區段中的 元素。
類別 ProviderSettings 代表特定組態群組,這些設定會新增至 providers
組態區段內的專案。 指示詞指定的 add
組態屬性通常包含名稱、類型和其他屬性。
建構函式
ProviderSettings() |
初始化 ProviderSettings 類別的新執行個體。 |
ProviderSettings(String, String) |
初始化 ProviderSettings 類別的新執行個體。 |