SectionInformation.UnprotectSection Method ()

 

Removes the protected configuration encryption from the associated configuration section.

Namespace:   System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)

public void UnprotectSection()

For more information about protected configuration sections, see Encrypting Configuration Information Using Protected Configuration.

The following example shows how to use this method.

static public void UnProtectSection()
{

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


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


    // Unprotect (decrypt)the section.
    section.SectionInformation.UnprotectSection();

    // Force the section information to be written to
    // the configuration file.
    section.SectionInformation.ForceDeclaration(true);

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

    config.Save(ConfigurationSaveMode.Full);

    // Display the decrypted configuration 
    // section. 
    string sectionXml =
        section.SectionInformation.GetRawXml();

    Console.WriteLine("Decrypted section:");
    Console.WriteLine(sectionXml);

}

.NET Framework
Available since 2.0
Return to top
Show: