encryption - C# - How to retrieve a connectionString from an App.config, Encrypting config sections -
i have configuration file looks super simple this:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionstrings> <add name="sqlserverconnectionstring" connectionstring="connection1"/> <add name ="oracleserverconnectionstring" connectionstring="connection2"/> </connectionstrings> </configuration>
it couldn't easier that. trying encrypt "connectionstrings" section. i've tried , tried following many online turotrials have not been able work. think have possibly found root of issue. when this:
string conectionstring = configurationmanager.connectionstrings["sqlserverconnectionstring"].connectionstring;
i am able expected result of "connection1".
however, when this:
var appconfigdir = @"c:\users\me\desktop\myproject\app.config"; system.configuration.configuration config = configurationmanager.openexeconfiguration(appconfigdir); connectionstringssection section = config.getsection("connectionstrings") connectionstringssection; var connectionstring = section.connectionstrings["sqlserverconnectionstring"];
i keep getting null! can me this? can't understand why unable connection string using second method.
i trying encrypt "app.config" doing following
section.sectioninformation.protectsection("dataprotectionconfigurationprovider");
this works, when decrypt:
section.sectioninformation.unprotectsection();
i unable origional connection strings. blank "connectionstring" section.
Comments
Post a Comment