-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsample2.vb
More file actions
40 lines (40 loc) · 1.8 KB
/
sample2.vb
File metadata and controls
40 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Protected Sub EncryptConnStrings_Click(sender As Object, e As EventArgs) _
Handles EncryptConnStrings.Click
'Get configuration information about Web.config
Dim config As Configuration = _
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
' Let's work with the <connectionStrings> section
Dim connectionStrings As ConfigurationSection = _
config.GetSection("connectionStrings")
If connectionStrings IsNot Nothing Then
' Only encrypt the section if it is not already protected
If Not connectionStrings.SectionInformation.IsProtected Then
' Encrypt the <connectionStrings> section using the
' DataProtectionConfigurationProvider provider
connectionStrings.SectionInformation.ProtectSection( _
"DataProtectionConfigurationProvider")
config.Save()
' Refresh the Web.config display
DisplayWebConfig()
End If
End If
End Sub
Protected Sub DecryptConnStrings_Click(sender As Object, e As EventArgs) _
Handles DecryptConnStrings.Click
' Get configuration information about Web.config
Dim config As Configuration = _
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
' Let's work with the <connectionStrings> section
Dim connectionStrings As ConfigurationSection = _
config.GetSection("connectionStrings")
If connectionStrings IsNot Nothing Then
' Only decrypt the section if it is protected
If connectionStrings.SectionInformation.IsProtected Then
' Decrypt the <connectionStrings> section
connectionStrings.SectionInformation.UnprotectSection()
config.Save()
' Refresh the Web.config display
DisplayWebConfig()
End If
End If
End Sub