I have defined in my web.config the following:
<appSettings file="settings.config" >
</appSettings>
It works just fine, but my question is, how to i modify it at runtime?
If i use:
开发者_高级运维WebConfigurationManager.OpenWebConfiguration("~/");
This actually modifies my web.config.
I have a few entries in my custom configuration file i would like to edit.
Any thoughts or pointers would be greatly appreciated :)
You need to give virtual path to your external config file. So it would be something like
var config = WebConfigurationManager.OpenWebConfiguration("/settings");
var appSettings = config.AppSettings.Settings;
or
var config = WebConfigurationManager.OpenWebConfiguration("/settings.config");
var appSettings = config.AppSettings.Settings;
Further, restartOnExternalChanges attribute on the section element would control if application would restart on configuration changes.
精彩评论