ProtectedConfigurationSection 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
구성 섹션에 configProtectedData 프로그래밍 방식으로 액세스할 수 있도록 합니다. 이 클래스는 상속할 수 없습니다.
public ref class ProtectedConfigurationSection sealed : System::Configuration::ConfigurationSection
public sealed class ProtectedConfigurationSection : System.Configuration.ConfigurationSection
type ProtectedConfigurationSection = class
inherit ConfigurationSection
Public NotInheritable Class ProtectedConfigurationSection
Inherits ConfigurationSection
- 상속
예제
다음 구성 파일에서는 보호된 데이터 공급자를 선언적으로 지정하는 방법을 보여 줍니다.
<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>
다음 코드 예제에서는 클래스를 사용하여 구성 파일 섹션의 ProtectedConfigurationSection 값에 프로그래밍 방식으로 액세스하는 configProtectedData 방법을 보여 줍니다.
using System;
using System.IO;
using System.Configuration;
namespace Samples.Aspnet
{
// Shows how to use ProtectedConfigurationSection.
class UsingProtectedConfigurationSection
{
static void GetDefaultProvider()
{
try
{
// Get the application configuration.
Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Get the protected configuration section.
ProtectedConfigurationSection pcSection =
(System.Configuration.ProtectedConfigurationSection)
config.GetSection("configProtectedData");
// Get the current DefaultProvider.
Console.WriteLine(
"Protected configuration section default provider:");
Console.WriteLine(" {0}", pcSection.DefaultProvider);
}
catch (ConfigurationErrorsException e)
{
Console.WriteLine(e.ToString());
}
}
static void GetProviderCollection()
{
try
{
// Get the application configuration.
Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Get the protected configuration section.
ProtectedConfigurationSection pcSection =
(System.Configuration.ProtectedConfigurationSection)
config.GetSection("configProtectedData");
Console.WriteLine(
"Protected configuration section providers:");
foreach (ProviderSettings ps in
pcSection.Providers)
{
Console.WriteLine(" {0}", ps.Name);
}
}
catch (ConfigurationErrorsException e)
{
Console.WriteLine(e.ToString());
}
}
public static void Main()
{
GetDefaultProvider();
GetProviderCollection();
}
}
}
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
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
Public Shared Sub Main()
GetDefaultProvider()
GetProviderCollection()
End Sub
End Class
설명
구성 파일 섹션에는 configProtectedData 해당 요소에 보호된 데이터 공급자 컬렉션이 포함되어 있습니다 providers .
메모
Aspnet_regiis.exe 도구를 사용하여 구성 섹션을 암호화하고 암호를 해독할 수 있습니다.
생성자
| Name | Description |
|---|---|
| ProtectedConfigurationSection() |
기본 설정을 사용하여 클래스의 새 인스턴스를 ProtectedConfigurationSection 초기화합니다. |