Ce sujet n'a pas encore été évalué - Évaluez ce sujet

ProtectedConfigurationSection, classe

Mise à jour : novembre 2007

Fournit l'accès par programme à la section de configuration configProtectedData. Cette classe ne peut pas être héritée.

Espace de noms :  System.Configuration
Assembly :  System.Configuration (dans System.Configuration.dll)

public sealed class ProtectedConfigurationSection : ConfigurationSection
public final class ProtectedConfigurationSection extends ConfigurationSection
public final class ProtectedConfigurationSection extends ConfigurationSection

La section du fichier de configuration configProtectedData contient une collection de fournisseurs de données protégées dans son élément providers.

Remarque :

Vous pouvez utiliser l'outil Aspnet_regiis.exe pour chiffrer et déchiffrer les sections de configuration. Consultez Chiffrement des informations de configuration à l'aide de la configuration protégée.

L'extrait de fichier de configuration suivant indique comment spécifier de façon déclarative des fournisseurs de données protégées.

<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>

L'exemple de code suivant montre comment utiliser la classe ProtectedConfigurationSection pour accéder par programme aux valeurs de la section du fichier de configuration 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();
        }
    }
} 


Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.