Stopping asp net web-config inheritance

Life is 10% what happens to us and 90% how we react to it. If you don't build your dream, someone else will hire you to help them build theirs.

Stopping asp net web-config inheritance

If you are running a site which may have an application at the root and other separate applications running in sub or virtual directories, then Settings of web.config inheritance could be a problem, this can be overcome by using location tag in root web.config

You can’t stop a child app from inheriting the web.config from the parent. You can only tell the parent to NOT inherit into any child.

The following example shows how to use this attribute in a configuration file to specify that the settings defined in the location element for the root of a Web site should not be inherited by child applications:

<location path="." inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>

you cannot simply add the line:

<location path="." inheritInChildApplications="false">

just below <configuration>. Instead, you need to wrap the individual web.config sections for which you want to disable inheritance. For example:

<!-- disable inheritance for the connectionStrings section -->
  <location path="." inheritInChildApplications="false">
  <connectionStrings>
  </connectionStrings>
  </location>

<!-- leave inheritance enabled for appSettings --> <appSettings> </appSettings>

<!-- disable inheritance for the system.web section --> <location path="." inheritInChildApplications="false"> <system.web> <webParts> </webParts> <membership> </membership>

<compilation> </compilation> </system.web> </location>

While <clear /> may work for some configuration sections, there are some that instead require a <remove name=”…”> directive, and still others don’t seem to support either. In these situations, it’s probably appropriate to set inheritInChildApplications=”false”.