Run a Different Version of ASP.NET as a Child Application in IIS

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=4.0.0.0, 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.
To get around the inheritance issues from a .NET 4 parent application to a .NET 2 (or 3 or 3.5) child application (without having to make a bunch of changes to the parent Web.config file), take advantage of the little-known inheritInChildApplications attribute of the <location> element. You can wrap the <location> element around your parent Web.config’s <system.web> element to prevent configuration inheritance down the hierarchy for the <system.web> configuration settings. Just make sure  you put in the appropriate <system.web> configuration settings in your child Web.config file.

Example

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">
<system.web>…</system.web>
</location>
[/sourcecode]

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.

Comments are closed.

Sign in
classic
Forgot password?
×
Sign up

(*) Required fields

I agree with OptimaSales Terms & Privacy Policy

×