SectionInformation.ProtectSection Method

Note: This method is new in the .NET Framework version 2.0.

Marks a configuration section for protection.

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

Public Sub ProtectSection ( _
	protectionProvider As String _
Dim instance As SectionInformation
Dim protectionProvider As String

public void ProtectSection (
	String protectionProvider
public function ProtectSection (
	protectionProvider : String



The name of the protection provider to use.

The ProtectSection method marks the section for encryption so it will be written in encrypted form on disk.

The following protection providers are included by default:

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

The following code example shows how to use the ProtectSection method.

Public Shared Sub ProtectSection() 
    ' Get the current configuration file.
    Dim config _
    As System.Configuration.Configuration = _
    ConfigurationManager.OpenExeConfiguration( _

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

End Sub 'ProtectSection

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0