Thanks adding the "xmlns=..." worked! I had another problem which may go hand-in-hand for other people, too. So I'm going to list it here.
I also had the problem when I ran my website, it generated the error:
Parser Error Message: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Bad Data
Turns out that RSA encryption cannot be used on a shared hosting web-site because – well here's the note from their knowledge base:
RSA key encryption is not supported in a shared environment since it exposes server key which is essential for encrypting the connection string in web.config file. Hence, it is not possible to encrypt connection strings in web.config file.
Basically, this code goes into the global.asax.cs file (in VS, I added the global.asax file and here are the code snippets that went into this file (global.asax.cs):
TennChris
Member
3 Points
2 Posts
Re: configProtectionProvider not allowed in <connectionStrings> in Web.config
Feb 22, 2012 07:03 PM|LINK
Thanks adding the "xmlns=..." worked! I had another problem which may go hand-in-hand for other people, too. So I'm going to list it here.
I also had the problem when I ran my website, it generated the error:
Parser Error Message: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Bad Data
Turns out that RSA encryption cannot be used on a shared hosting web-site because – well here's the note from their knowledge base:
RSA key encryption is not supported in a shared environment since it exposes server key which is essential for encrypting the connection string in web.config file. Hence, it is not possible to encrypt connection strings in web.config file.
So another approach is to encrypt the web.config file programmatically when the web app runs for the first time. I got the idea from this forum post that describes how to do this: http://stackoverflow.com/questions/5602630/encrypting-web-config-and-installing
Basically, this code goes into the global.asax.cs file (in VS, I added the global.asax file and here are the code snippets that went into this file (global.asax.cs):
using System.Web.Configuration;
using System.Configuration;
using System.Web.Hosting;
protected void Application_Start(object sender, EventArgs e)
{
//Test to see if this app is being started on the development machine (e.g. in the debugger)
//This code will encript web.config the first time this program runs.
//Therefore, it is important to have a backup copy of the non-encrypted web.config as this
//code below will encrypt it, which is what we want to happen on the production server.
if (! System.Diagnostics.Debugger.IsAttached )
{
EncryptConfig(); //See below
}
}
/// <summary>
/// This technique of encrypting the web.config file was learned from this forum post:
/// http://stackoverflow.com/questions/5602630/encrypting-web-config-and-installing
/// </summary>
private static void EncryptConfig()
{
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);
foreach (string sectionName in new[] { "connectionStrings", "appSettings" })
{
ConfigurationSection section = config.GetSection(sectionName);
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
}
config.Save();
}