开发者

Web.Config <appSettings file=""> question

开发者 https://www.devze.com 2023-01-30 03:56 出处:网络
I have defined in my web.config the following: <appSettings file=\"settings.config\" > </appSettings>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消