使用.NET ConfigurationManager中读取一个字符串,而不是一个app.config文件设置 [英] Using .NET ConfigurationManager to read settings from a string instead of an app.config file

查看:236
本文介绍了使用.NET ConfigurationManager中读取一个字符串,而不是一个app.config文件设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在运行我们在我们的数据中心不同的机器服务(如.exe文件来实现)的多个实例。但是,我们想用来存储配置参数在一个中央位置该.exe文件(而不是在每台机器上.exe.config是)。

We are running multiple instances of our service (implemented as a .exe file) on different machines in our data center. However, we would like to store configuration parameters for this .exe file in a central location (as opposed to being in the .exe.config per machine).

要做到这一点,我们计划到.exe.config文件的内容移动到一个属性在中央存储库(Active Directory或SQL),并做成了。 exe文件的所有机器上运行此存储库中读取。

To do this, we are planning to move the content of the .exe.config files to an attribute in a central repository (Active Directory or SQL) and make the .exe's running on all machines read from this repository.

我想重用所有用于读/写配置信息现有的类(使用ConfigurationManager中,的ConfigurationProperty等,基本上都采用整个.NET配置框架) - 但是,而不是从.exe.config文件与(其中它在默认情况下加载它 - 我希望它从XML BLOB,我将检索从中央存储库的字符串值加载它

I would like reuse all the existing classes used for reading/writing configuration information (using ConfigurationManager, ConfigurationProperty etc., basically using the entire .NET Configuration framework) - however, instead of loading it from the .exe.config file (which it does by default - I want it to load it from a string value of the XML blob that I will retrieve from that central repository.

我想办法使用ConfigurationManager中的API来做到这一点,但无法找到任何可以从字符串加载配置部分。任何指针?

I was trying to find ways to do it using the ConfigurationManager API but couldn't find anything that could load a Configuration Section from a string. Any pointers?

推荐答案

虽然我怀疑这是它的目的是为中,我们使用的 ProtectedConfigurationProvider 。基本上,这个类应该允许你加密的配置文件,但我们只是有解密的方法连接到我们的数据库返回的配置信息。请参见获取笔记上实施。这感觉有点哈克,但我们找不到完全没有重写所有的配置解析逻辑的任何其他方式。

Although I doubt this is what it was intended for, we've done this in our project using ProtectedConfigurationProvider. Basically, this class is supposed to allow you to encrypt your configuration file but we simply have the Decrypt method connect to our database and return the configuration information. See this for notes on implementing. This felt a little hacky, but we couldn't find any other way without completely rewriting all of the configuration parsing logic.

这篇关于使用.NET ConfigurationManager中读取一个字符串,而不是一个app.config文件设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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