0

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

Community
  • 1
  • 1
Nad
  • 4,605
  • 11
  • 71
  • 160
  • I believe that you do not have correctly setup the encryption for the connection string. Please consider this answers -> https://stackoverflow.com/questions/42115/app-config-connection-string-protection-error – Aristos Aug 27 '18 at 06:48
  • @Aristos: what kind of setup ? didnt got you – Nad Aug 27 '18 at 06:51
  • I have add a link on previous answer, with the details... – Aristos Aug 27 '18 at 07:18
  • @Aristos: now got it, but where to add this part which will give me rights to access that class `aspnet_regiis -pa "NetFrameworkConfigurationKey" "{domain}\{user}"` ?? – Nad Aug 27 '18 at 07:24

0 Answers0