How to prevent web.config inheritance in ASP.NET

Posted by Mikael Östberg | Filed under ,

While setting up this blog, I ran into a configuration issue.

I wanted the blog to be on the URL devva.net/blog so I thought a Virtual Directory would do the trick.

On the root of devva.net, I'm currently running N2CMS. That CMS has the possibility to run several sites in the same installation and I didn't want all of the other sites to have /blog. Neither did I want to run two separate copies of the CMS code.

The solution was a new Web site in IIS pointing the home directory to the CMS Web site directory and then a Virtual Directory pointing to the directory containing BlogEngine.NET.

The problem with that is that the Virtual Directory inherits all the configuration settings from the Web.config in N2CMS, running in the root. This led to several problems like HttpHandlers not being found and such, which isn't strange at all. However, I still wanted this particular setup, so I started looking around on how to prevent web.config settings inheritance from an IIS WebSite to a child Virtual Directory and found a very good solution from Rick Strahl.

As stated in his post, I wrapped the <system.web> section in Web.config with <location inheritInChildApplications="false"> which solved the inheritance problem and as you can see, this blog is working perfectly.