可以在web.config中从外部XML文件中读取? [英] Can a web.config read from an external xml file?
问题描述
我要复制web.config文件之间的一些设置(如连接字符串),一个WCF主机使用和网络客户端使用web.config文件。
I have to duplicate some settings (like connection string) between a web.config file that a WCF host uses and a web.config file that a web client uses.
在不重复的兴趣,我可以同时拥有从单独的XML文件中读取web.configs?这两个web.configs可以在完全不同的解决方案/项目,所以我想这是不可能的,但希望得到对方的意见。
In the interest of not duplicating, can I have both the web.configs read from a separate xml file? The two web.configs can be entirely in different solutions/projects so I guess this is not possible, but wanted to get other's opinion.
PS:我明白,我可以使用一个数据库来存储所有的配置设置。
PS: I do understand I can use a database to store all the config settings.
推荐答案
是的,任何配置的栏目可以是外部化 - 这包括像<的appSettings>
,<是connectionStrings方式>
和多
Yes, any configuration section can be "externalized" - this includes things like <appSettings>
, <connectionStrings>
and many more.
您就会有这样的事情在你的web.config:
You'd have something like this in your web.config:
<configuration>
<appSettings configSource="appSettings.config" />
<connectionStrings configSource="connectionStrings.config" />
<system.web>
<pages configSource="pages.config" />
<httpHandlers configSource="httphandlers.config">
</system.web>
</configuration>
外向配置的也只是包含在其中个子节:
The externalized config's would just contain that one subsection in them:
httphandlers.config:
httphandlers.config:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
请注意,你不能外部化整个&LT;的System.Web&GT;
部分,因为这是一个配置部分组 - 不是配置部分 - 但你可以外部化的大部分子板块含有的System.Web中。
Note you cannot externalize the entire <system.web>
part, since that is a configuration section group - not a configuration section - but you can externalize most of the sub-sections contained in system.web.
这篇关于可以在web.config中从外部XML文件中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!