使用英语阅读

通过


ProtectedConfiguration 类

定义

为当前应用程序的配置文件提供对受保护配置提供程序的访问。

C#
public static class ProtectedConfiguration
继承
ProtectedConfiguration

示例

以下示例演示如何使用 ProtectedConfiguration 类检索受保护配置提供程序的集合,并发现其提供程序名称、RSA 提供程序名称和节名称。

C#
using System;
using System.Configuration;
using System.Collections;
using System.Security.Permissions;

namespace Samples.AspNet
{
  
    // Show how to use the ProtectedConfiguration.
    public sealed class UsingProtectedConfiguration
    {

        [PermissionSet(SecurityAction.Demand, Name="FullTrust")]    
     private static void GetProviders()
        {
            // Get the providers' collection.
            ProtectedConfigurationProviderCollection
                providers = ProtectedConfiguration.Providers;

            IEnumerator pEnum =
                providers.GetEnumerator();

            foreach (ProtectedConfigurationProvider provider in
                providers)
            {
                Console.WriteLine
                    ("Provider name: {0}",
                      provider.Name);
                Console.WriteLine
                         ("Provider description: {0}",
                          provider.Description);
            }
        }

       [PermissionSet(SecurityAction.Demand, Name="FullTrust")]    
    private static void GetProviderName()
        {
            // Get the current provider name.
            string dataProtectionProviderName =
               ProtectedConfiguration.DataProtectionProviderName;
            Console.WriteLine(
                "Data protection provider name: {0}",
                 dataProtectionProviderName);

            // Get the Rsa provider name.
            string rsaProviderName =
                ProtectedConfiguration.RsaProviderName;
            Console.WriteLine(
                "Rsa provider name: {0}",
                 rsaProviderName);

            // Get the protected section name.
            string protectedSectionName =
                ProtectedConfiguration.ProtectedDataSectionName;
            Console.WriteLine(
                "Protected section name: {0}",
                 protectedSectionName);
        }

        static void Main(string[] args)
        {

            // Get current and Rsa provider names.
            GetProviderName();

            // Get the providers' collection.
            GetProviders();
        }
    }    
}

注解

ProtectedConfiguration 允许你获取有关可用于保护敏感配置数据的提供程序的信息。 通常使用标准提供程序,但也可以通过从 ProtectedConfigurationProvider 类派生来创建自定义提供程序。

有关受保护配置的详细信息,请参阅 使用受保护的配置加密配置信息

字段

DataProtectionProviderName

数据保护提供程序的名称。

ProtectedDataSectionName

受保护的数据节的名称。

RsaProviderName

RSA 提供程序的名称。

属性

DefaultProvider

获取默认受保护配置提供程序的名称。

Providers

获取安装的受保护配置提供程序的集合。

适用于

产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅