Aracılığıyla paylaş


SectionInformation.ProtectSection(String) Yöntem

Tanım

Koruma için bir yapılandırma bölümünü işaretler.

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

Parametreler

protectionProvider
String

Kullanılacak koruma sağlayıcısının adı.

Özel durumlar

AllowLocation özelliği false olarak ayarlanmıştır.

-veya-

Hedef bölüm zaten korumalı bir veri bölümüdür.

Örnekler

Aşağıdaki örnekte yönteminin nasıl kullanılacağı gösterilmektedir 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

Açıklamalar

yöntemi, ProtectSection diskte şifrelenmiş biçimde yazılması için bölümü şifreleme için işaretler.

Aşağıdaki koruma sağlayıcıları varsayılan olarak dahil edilir:

DpapiProtectedConfigurationProvider

RsaProtectedConfigurationProvider

Not

yöntemini bir parametre veya boş bir null dize ile çağırırsanızProtectSection, RsaProtectedConfigurationProvider sınıfı koruma sağlayıcısı olarak kullanılır.

Korumalı yapılandırma bölümleri hakkında daha fazla bilgi için bkz. Korumalı Yapılandırma Kullanarak Yapılandırma Bilgilerini Şifreleme.

Şunlara uygulanır

Ayrıca bkz.