开发者

Web.Config <appSettings file=""> question

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜