Is it possible to have separate config files for specific sections of the web.config? Specifically I’d like to move IIS 7’s rewrite section out of the web.config and into it’s own config file.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can certainly move your rewrite rules and mappings out to a separate file:
<system.webServer> <rewrite> <rewriteMaps configSource="rewritemaps.config" /> <rules configSource="rewriteRules.config" /> </rewrite> </system.webServer>
In addition you can move quite a few configuration sections to their own files:
<appSettings configSource="appSettings.config" />[Docs]
<connectionStrings configSource="connectionStrings.config"/>[Docs]
<pages configSource="pages.config"/>[Docs]
For more info see this page which will help you decide if a configuration section can be stored externally:
Method 2
Yes, this is possible.
For each configuration section, you can set the configSource attribute to the location (file) where you are holding the configuration.
E.g.:
<appSettings configSource="appSettings.config" />
And in appSettings.config:
<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
<add key="myKey" value="myValue" />
</appSettings>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0