简体   繁体   中英

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.

I'd like to have another web.config in the root eg custom.web.config.

The web.config one is generated by an external tool and I can't change it; I'd put our custom config settings in the custom.web.config file.

ASP.NET only loads the first web.config by default obviously.

How to configure these so that ASP.NET combines both config files and use both?

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.

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.

How would that be possible?

Thanks

Use ConfigSource in main config file to refer sections which are defined in your second config file.

Check out this example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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