SectionInformation.ProtectSection(String) Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Markiert einen Konfigurationsabschnitt zum Schutz.
public:
void ProtectSection(System::String ^ protectionProvider);
public void ProtectSection(string protectionProvider);
member this.ProtectSection : string -> unit
Public Sub ProtectSection (protectionProvider As String)
Parameter
- protectionProvider
- String
Der Name des zu verwendenden Schutzanbieters.
Ausnahmen
Die AllowLocation-Eigenschaft ist auf false gesetzt.
- oder -
Der Zielabschnitt ist bereits ein geschützter Datenabschnitt.
Beispiele
Das folgende Beispiel zeigt, wie die ProtectSection Methode verwendet wird.
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
Hinweise
Die ProtectSection Methode kennzeichnet den Abschnitt für die Verschlüsselung, sodass er in verschlüsselter Form auf dem Datenträger geschrieben wird.
Die folgenden Schutzanbieter sind standardmäßig enthalten:
DpapiProtectedConfigurationProvider
RsaProtectedConfigurationProvider
Hinweis
Wenn Sie die ProtectSection Methode mit einem null Parameter oder einer leeren Zeichenfolge aufrufen, wird die RsaProtectedConfigurationProvider Klasse als Schutzanbieter verwendet.