The Forgotten Web.Config Inheritance Elegance

When you are running multiple Web Applications on a server you sometimes bumped into a challenge that the web.config are cumulative.  This can make life sweet for some things, for example you only need to specify the SMTP server settings once, in the root web.config.

 

There can be other times when you wish to have only a percentage of the parent web.config inherited into your application. The magic control element is <location>.

 

You may put this around any child element of <configuration>(remembering to keep it valid XML) and then include or exclude elements.

 

<configuration>
    <location path="PublicSite">
        <system.web>
            <!-- settings for "PublicSite" go here... -->
        </system.web>
    </location>
    <location path="PrivateSite">
        <system.web>
            <!-- settings for "PrivateSite" go here... -->
        </system.web>
    </location>
    <location path="." inheritInChildApplications="false">
        <system.web>
        </system.web>
    </location>
</configuration>

The MSDN Documentation is here. It applies to Net 2.0 and later. It would be nice if it could be placed around any element .. hint hint hint to MSFT.

Comments

Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape