We have a customer that hosts one of our web applications on Windows Server 2003/IIS 6. During a support session recently, I noticed that the customer has a unique setup that I had not seen before. To preserve legacy URLs, the customer deploys this application as a virtual directory under the IIS Default Web Site. This isn’t unique by itself until I noticed that the Default Web Site uses ASP.NET 4.0 instead of ASP.NET 2.0, which is the version of ASP.NET our application typically runs on. As I was troubleshooting an issue that I thought might be related to running our application on ASP.NET 4 instead of 2, I noted some interesting things.
- Changing the virtual directory for our application to run on .NET 2 worked fine in IIS even though the parent runs on .NET 4.
- Our application has a separate application pool so there is no conflict between the parent site and child virtual directory.
- The application incurred a Web.config parser error after the .NET 2 change: Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive. The targetFramework attribute is inherited from a Web.config file in the Default Web Site root using ASP.NET configuration inheritance.
- Removing the targetFramework attribute led to some other parser errors like Could not load file or assembly ‘System.Data.Linq, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies. The system cannot find the file specified. Again, these are related to .NET 4 vs. .NET 2 issues.
This technique will work for .NET 2.0 and later as well as on IIS 6, IIS 7 and IIS 7.5. You can wrap individual sections like the <system.web> element or even several sections at a time using the <location> element as long as you have a well-formed XML document.[sourcecode language=”html”] <location path="." inheritInChildApplications="false">
Check out the Stopping ASP.NET web.config inheritance article for more illustrations of stopping inheritance using the <location> element and this is a great way to run different versions of ASP.NET applications in a nested virtual directory structure.