简体   繁体   English

如何以编程方式在同一文件夹中加载和合并2个web.config文件?

[英]How to load and merge 2 web.config files in the same folder programmatically?

I have an asp.net application with one web.config in the root. 我有一个asp.net应用程序,根目录中有一个web.config。

I'd like to have another web.config in the root eg custom.web.config. 我想在root中有另一个web.config,例如custom.web.config。

The web.config one is generated by an external tool and I can't change it; web.config one由外部工具生成,我无法更改它; I'd put our custom config settings in the custom.web.config file. 我将自定义配置设置放在custom.web.config文件中。

ASP.NET only loads the first web.config by default obviously. ASP.NET显然默认只加载第一个web.config。

How to configure these so that ASP.NET combines both config files and use both? 如何配置这些以便ASP.NET结合两个配置文件并同时使用它们?

I can't put the custom.web.config (named web.config) in a subfolder since in which case only the pages in that subfolders use it. 我不能将custom.web.config(名为web.config)放在子文件夹中,因为在这种情况下只有该子文件夹中的页面使用它。

I thought perhaps there is a way to load both web.config and custom.web.config files at runtime and merge them so that ConfigManager looks at both always. 我想也许有一种方法可以在运行时加载web.config和custom.web.config文件并合并它们,以便ConfigManager始终查看它们。

How would that be possible? 怎么可能呢?

Thanks 谢谢

Use ConfigSource in main config file to refer sections which are defined in your second config file. 在主配置文件中使用ConfigSource来引用在第二个配置文件中定义的部分。

Check out this example 看看这个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM