I encrypted the AppSettings part of my web.config, tested it on my machine, and it worked, but when I downloaded it to use it on the Internet, it gave me an error:
Configuration Error Description: An error occurred while processing the configuration file necessary to service this request. Please read the specific error details below and modify the configuration file accordingly.
Parser error message: could not be decrypted using the provider 'DataProtectionConfigurationProvider. Provider error message: The key is not valid for use in the specified state. (Exception from HRESULT: 0x8009000B)
Line 24: <appSettings configProtectionProvider="DataProtectionConfigurationProvider"> Line 25: <EncryptedData>
I used the following sub for encryption:
Private Sub ProtectSection(ByVal sectionName As String, ByVal provider As String) Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath) Dim section As ConfigurationSection = config.GetSection(sectionName) If section IsNot Nothing AndAlso Not section.SectionInformation.IsProtected Then section.SectionInformation.ProtectSection(provider) config.Save() End If End Sub
source share