ProtectedConfigurationSection Class
Provides programmatic access to the configProtectedData configuration section. This class cannot be inherited.
Assembly: System.Configuration (in System.Configuration.dll)
The configProtectedData configuration file section contains a collection of protected data providers in its providers element.
Note: |
|---|
You can use the Aspnet_regiis.exe tool to encrypt and decrypt configuration sections. See Encrypting Configuration Information Using Protected Configuration. |
The following configuration file excerpt shows how to declaratively specify protected data providers.
<configProtectedData defaultProvider="RsaProtectedConfigurationProvider">
<providers>
<clear />
<add keyContainerName="NetFrameworkConfigurationKey" cspProviderName="" useMachineContainer="true" useOAEP="false" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" name="RsaProtectedConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add useMachineProtection="true" description="Uses CryptProtectData and CryptUnProtectData Windows APIs to encrypt and decrypt" keyEntropy="" name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</configProtectedData>
The following code example shows how to use the ProtectedConfigurationSection class to programmatically access values in the configProtectedData configuration file section.
Imports System Imports System.IO Imports System.Configuration ' Shows how to use ProtectedConfigurationSection. Class UsingProtectedConfigurationSection Shared Sub GetDefaultProvider() Try ' Get the application configuration. Dim config As Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) ' Get the protected configuration section. Dim pcSection _ As ProtectedConfigurationSection = _ CType(config.GetSection( _ "configProtectedData"), _ System.Configuration.ProtectedConfigurationSection) ' Get the current DefaultProvider. Console.WriteLine( _ "Protected configuration section default provider:") Console.WriteLine("{0}", _ pcSection.DefaultProvider) Catch e As ConfigurationErrorsException Console.WriteLine(e.ToString()) End Try End Sub 'GetDefaultProvider Shared Sub GetProviderCollection() Try ' Get the application configuration. Dim config As Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) ' Get the protected configuration section. Dim pcSection _ As ProtectedConfigurationSection = _ CType(config.GetSection( _ "configProtectedData"), _ System.Configuration.ProtectedConfigurationSection) Console.WriteLine( _ "Protected configuration section providers:") Dim ps As ProviderSettings For Each ps In pcSection.Providers Console.WriteLine(" {0}", ps.Name) Next ps Catch e As ConfigurationErrorsException Console.WriteLine(e.ToString()) End Try End Sub 'GetProviderCollection Public Shared Sub Main() GetDefaultProvider() GetProviderCollection() End Sub 'Main End Class 'UsingProtectedConfigurationSection
System.Configuration.ConfigurationElement
System.Configuration.ConfigurationSection
System.Configuration.ProtectedConfigurationSection
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: