如何从自定义位置读取app.config,即从.NET中的数据库读取 [英] How to read app.config from a custom location, i.e. from a database in .NET

查看:403
本文介绍了如何从自定义位置读取app.config,即从.NET中的数据库读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图覆盖我的自定义ServiceHost中的ApplyConfiguration方法从数据库读取配置,而不是app.config。理想情况下,我希望能够这样做:



配置config = GetConfigFromMyDatabase(...);



ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);



有没有办法这样做而不写一个临时app.config文件?

解决方案

使用:

  System.Configuration .ConfigurationManager.OpenExeConfiguration(string exePath)

这样应该可以打开一个任意的app.config文件。 / p>

I am trying to override the ApplyConfiguration method in my custom ServiceHost to read the configuration from a database instead of app.config. Ideally I would want to be able to do something like this:

Configuration config = GetConfigFromMyDatabase(...);

ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);

Is there any way to do this without writing a temp app.config file?

解决方案

What about using:

System.Configuration.ConfigurationManager.OpenExeConfiguration(string exePath)

That should let you open an arbitrary app.config file.

这篇关于如何从自定义位置读取app.config,即从.NET中的数据库读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆