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 类的新实例。 |