从单独的配置文件中读取设置 [英] Reading settings from separate config file

查看:150
本文介绍了从单独的配置文件中读取设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的asp.net应用程序已经使用了常见的配置一个web.config。我也有一些数据对象映射到连接字符串的一部分,这部分将是线对夫妇一千。我想搬到那款到另一个配置文件dataMappings.config,所以我不壮实的web.config - ?有没有访问该配置文件的标准机制

My asp.net app has is using a web.config for common configuration. I also have a section that maps some data objects to connection strings, and that section is going to be couple thousand of lines. I want to move that section to another config file "dataMappings.config", so I don't bulk up web.config - is there a standard mechanism of accessing that config file?

感谢您,
安德烈

Thank you, Andrey

推荐答案

在每一部分中,您可以定义 configSource ,它可以指向外部文件的路径。这里有一个简单的例子:

In each section, you can define configSource, which can point to an external file path. Here's a simple example:

<connectionStrings configSource="myConnectionStrings.Config" />
<appSettings configSource="myAppSettings.Config" />

只要确保不使用的.xml 文件的扩展名,因为它可以在浏览器中查看。 的.config 不会由Web服务器提供服务。

Just make sure not to use .xml file extension since it can be viewed in a browser. .config will not be served by the web server.

由于你的配置节在web.config中仍定义(从而指向外部文件),您可以访问通过正常途径该信息( WebConfigurationManager.AppSettings WebConfigurationManager.GetSection ConfigurationManager中,或自定义节处理程序需要)

Because your config sections are still defined in the web.config (thus pointing to external files), you can access this information via the normal routes (WebConfigurationManager.AppSettings, WebConfigurationManager.GetSection, ConfigurationManager, or custom section handlers as needed)

这篇关于从单独的配置文件中读取设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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