0

I have an asp.net application with one web.config in the root.

I'd like to have another web.config in the root e.g. 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

The Light
  • 26,341
  • 62
  • 176
  • 258
  • 1
    I'd rethink the design and or deployment. What you want to do goes very much against how the framework and IIS expect from configuration. – Oded Nov 14 '12 at 11:42
  • http://stackoverflow.com/questions/719928/how-do-you-modify-the-web-config-appsettings-at-runtime looks like the closest you'll get to what you want. – spender Nov 14 '12 at 11:45
  • 2
    "is generated by an external tool and I can't change it" on such assumptions are built some of the greatest entries to http://thedailywtf.com/. Change the external tool, if maintained by someone else present your requirements. – Richard Nov 14 '12 at 11:45

1 Answers1

2

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

Check out this example

Emmanuel N
  • 7,350
  • 2
  • 26
  • 36