Thursday, June 2, 2011

Solving web.config conflicts in child ASP.NET web apps in subdirectories

It often happens that we want to host a .NET web app as a (virtual) subdirectory under another existing web application. For example, we have a parent web app at http://mywebapp.com and a child web app at http://mywebapp.com/admin/

Because of the way that configuration settings are inherited in ASP.NET, it can happen that the parent app web.config settings conflict with the child app web.config, leading to configuration errors in the child application. To solve this prolbem, we need to disable web.config inheritance in the web.config file of the parent application. This is done by wrapping the whole <system.web> section into a <location> element with the inheritInChildApplications attribute set to "false", like this:


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

Happy coding!

No comments:

Post a Comment