I like to update the keys / values defined in a section AppSettings Web.configat runtime. however, I DO NOT want to actually save them in a file Web.config.
I have a huge web application consisting of many modules, DLLs and source code files. A bunch of important information ranged from database configuration, encryption keys, username and passwords for web services, which are stored in a AppSettingsfile section Web.config. The last project requirement requires that I move these values from Web.configand store them in a safe vault.
I have already provided these values in an external location, and I can read them back when the application starts.
here is a sample code.
Global.asax
public class Global: System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
Dictionary<string, string> secureConfig = new Dictionary<string,string>{};
secureConfig.Add("ACriticalKey","VeryCriticalValue");
foreach (KeyValuePair<string, string> item in secureConfig) {
ConfigurationManager.AppSettings.Add(item.Key, item.Value);
}
}
}
As you noticed, it is impossible to change the links AppSettingsin the massive code created by several programming commands to read their settings from mine secureConfig dictionary, and on the other hand, I should not save these values in Web.configwhich is accessible to web administrators and operators, system administrators and administrators the clouds.
To make life easier for programmers, I want them to add their values to the section AppSettings Web.configduring development, but they will be removed from there and placed in a secure repository later during deployment, however, these values should be accessible to the transparent program, since they are still in section AppSettings.
: AppSettings , ConfigurationManager.AppSettings["ACriticalKey"], "VeryCriticalValue" Web.Config?
: ConfigurationManager.AppSettings.Add(item.Key, item.Value); ConfigurationErrorsException The configuration is read only.
. , AppSettings