Ler en inglés

Compartir por


ProtectedConfiguration Clase

Definición

Proporciona acceso a los proveedores de configuración protegida para el archivo de configuración de la aplicación actual.

C#
public static class ProtectedConfiguration
Herencia
ProtectedConfiguration

Ejemplos

En el ejemplo siguiente se muestra cómo usar la ProtectedConfiguration clase para recuperar una colección de proveedores de configuración protegidos y detectar su nombre de proveedor, el nombre del proveedor RSA y los nombres de sección.

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();
        }
    }    
}

Comentarios

La ProtectedConfiguration clase permite obtener información sobre los proveedores disponibles para proteger los datos de configuración confidenciales. Normalmente se usan los proveedores estándar, pero también se pueden crear proveedores personalizados derivando de la ProtectedConfigurationProvider clase .

Para obtener más información sobre la configuración protegida, vea Cifrado de información de configuración mediante la configuración protegida.

Campos

DataProtectionProviderName

Nombre del proveedor de protección de datos.

ProtectedDataSectionName

Nombre de la sección de datos protegidos.

RsaProviderName

Nombre del proveedor de RSA.

Propiedades

DefaultProvider

Obtiene el nombre del proveedor de configuración protegida predeterminado.

Providers

Obtiene una colección de los proveedores de configuración protegida instalados.

Se aplica a

Produto Versións
.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, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Consulte también