I want to Encrypt
my connectionstring while sending the source code for Viewing purpose. So I am doing something like this below in Global.asax
file.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
EncryptConnString();
}
public static void EncryptConnString()
{
Configuration config = System.Web.Configuration
.WebConfigurationManager
.OpenWebConfiguration("~");
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
config.Save();
}
}
but at this line config.Save();
I am getting some strange Error which is below
An exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll but was not handled in user code
Additional information: An error occurred executing the configuration section handler for connectionStrings.
I am unable to find the reason of it as it is the standard code to Encrypt it. Please suggest what might be the cause