I set up my website to have the ability to encrypt connection strings.
In IIS 6,
I could use the below code to encrypt them.
Now in IIS 7 I get this error
InvalidOperationException
Event handlers can only be bound to HttpApplication events during IHttpModule initialization.
I believe this has to do with IIS seven working a little differently. Not sure what I need to change in my code
Here's my code thanks
In IIS 6,
I could use the below code to encrypt them.
Now in IIS 7 I get this error
InvalidOperationException
Event handlers can only be bound to HttpApplication events during IHttpModule initialization.
I believe this has to do with IIS seven working a little differently. Not sure what I need to change in my code
Here's my code thanks
Code:
Imports System.Web.Configuration
Partial Class encryptconnect
Inherits System.Web.UI.Page
Protected Sub btnEncrypt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
Dim Config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim appSettings As ConfigurationSection = Config.ConnectionStrings
If Not appSettings.SectionInformation.IsProtected Then
appSettings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider")
appSettings.SectionInformation.ForceSave = True
Config.Save(ConfigurationSaveMode.Modified)
lblStatus.Text = "Connection Strings were changed and are now Currently Encrypted"
End If
End Sub
Protected Sub btnDecrypt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click
Dim Config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim appSettings As ConfigurationSection = Config.ConnectionStrings
If appSettings.SectionInformation.IsProtected Then
appSettings.SectionInformation.UnprotectSection()
appSettings.SectionInformation.ForceSave = True
Config.Save(ConfigurationSaveMode.Modified)
lblStatus.Text = "Connection Strings were Decrypted and are NOT Encrypted"
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim appSettings As ConfigurationSection = Config.ConnectionStrings
If appSettings.SectionInformation.IsProtected Then
lblStatus.Text = "Connection Strings are Currently Encrypted"
Else
lblStatus.Text = "Connection Strings are NOT Encrypted"
End If
End Sub
End Class