SectionInformation.ProtectSection(String) Méthode

Définition

Marque une section de configuration pour la protection.

public:
 void ProtectSection(System::String ^ protectionProvider);
public void ProtectSection (string protectionProvider);
member this.ProtectSection : string -> unit
Public Sub ProtectSection (protectionProvider As String)

Paramètres

protectionProvider
String

Nom du fournisseur de protection à utiliser.

Exceptions

La propriété AllowLocation a la valeur false.

- ou -

La section cible est déjà une section de données protégée.

Exemples

L'exemple suivant illustre l'utilisation de la méthode ProtectSection.

static public void ProtectSection()
{

    // Get the current configuration file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

    // Get the section.
    UrlsSection section =
        (UrlsSection)config.GetSection("MyUrls");

    // Protect (encrypt)the section.
    section.SectionInformation.ProtectSection(
        "RsaProtectedConfigurationProvider");

    // Save the encrypted section.
    section.SectionInformation.ForceSave = true;

    config.Save(ConfigurationSaveMode.Full);

    // Display decrypted configuration 
    // section. Note, the system
    // uses the Rsa provider to decrypt
    // the section transparently.
    string sectionXml =
        section.SectionInformation.GetRawXml();

    Console.WriteLine("Decrypted section:");
    Console.WriteLine(sectionXml);
}
Public Shared Sub ProtectSection() 
    
    ' Get the current configuration file.
    Dim config _
    As System.Configuration.Configuration = _
    ConfigurationManager.OpenExeConfiguration( _
    ConfigurationUserLevel.None)

    
    ' Get the section.
    Dim section As UrlsSection = _
    CType(config.GetSection("MyUrls"), UrlsSection)
    
    
    ' Protect (encrypt)the section.
    section.SectionInformation.ProtectSection( _
    "RsaProtectedConfigurationProvider")
    
    ' Save the encrypted section.
    section.SectionInformation.ForceSave = True
    
    config.Save(ConfigurationSaveMode.Full)
    
    ' Display decrypted configuration 
    ' section. Note, the system
    ' uses the Rsa provider to decrypt
    ' the section transparently.
    Dim sectionXml As String = _
    section.SectionInformation.GetRawXml()
    
    Console.WriteLine("Decrypted section:")
    Console.WriteLine(sectionXml)

End Sub

Remarques

La ProtectSection méthode marque la section pour le chiffrement afin qu’elle soit écrite sous forme chiffrée sur le disque.

Les fournisseurs de protection suivants sont inclus par défaut :

DpapiProtectedConfigurationProvider

RsaProtectedConfigurationProvider

Notes

Si vous appelez la ProtectSection méthode avec un null paramètre ou une chaîne vide, la RsaProtectedConfigurationProvider classe est utilisée comme fournisseur de protection.

Pour plus d’informations sur les sections de configuration protégée, consultez Chiffrement des informations de configuration à l’aide de la configuration protégée.

S’applique à

Voir aussi