Scott Hanselman

Changing ASP.NET web.config inheritance when mixing versions of child applications

March 26, '13 Comments [19] Posted in ASP.NET | Bugs | IIS
Sponsored By

Mixed Application Pools

My blog and all the sites in and around it are a mix of .NET 2.0, 3.5 and 4. This blog engine is currently .NET 3.5 and runs at http://hanselman.com/blog, but the application at http://hanselman.com/ (the root) is .NET 4.

You can happily mix and match applications across .NET versions on a single IIS instance. You can see how mixed my system is in the screenshot at right there.

However, things got messy when I changed the parent / application to .NET 4, but kept the child /blog as .NET 3.5 (the 2.0 CLR). I got lots of errors like

  • Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive. The targetFramework attribute was inherited from the root .NET 4 Web.config file in the Default Web Site root using ASP.NET configuration inheritance and confused the /blog .NET 2 application.

I didn't want to change the /blog applications' web.config. I just wanted to stop it from inheriting the settings from the parent application. Turns out you can wrap whole sections in a location tag, and then tell that scoped tag to prevent child applications from inheriting.

What you do is change the parent .NET 4 app's web.config to indicate its settings shouldn't flow down to the children, like the .NET 2/3.5 /blog app.

<location path="." inheritInChildApplications="false">
<system.web>
...your system.web stuff goes here
</system.web>
</location>

You can actually read about this in detail in the ASP.NET 4 "breaking changes" documentation. Of course YOU read those closely, don't you? ;)

I chose to change this settings for all of System.Web, but you could do it on a per-section basis if you preferred.

Hope this helps you!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Tuesday, March 26, 2013 11:05:51 AM UTC
So, does that mean we can put something as simple as

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

in the parent web.config and not have unrecognised attribute explosions? If so, you rock!
Dan F
Tuesday, March 26, 2013 11:44:52 AM UTC
Is it possible to do it the other way around? I find it strange that I have to update the parent, when it is the child who decides if the settings should be inherited or not.

Thomas Eyde
Tuesday, March 26, 2013 1:14:27 PM UTC
That also means that none of the children will be able to inherit the settings from parent/root.
Tuesday, March 26, 2013 2:52:11 PM UTC
It should be noted any setting NOT contained with in the location will pass down to all child applications. We've had to find this out the hard way with a SSO application that we recently wrote.
Scott Lance
Tuesday, March 26, 2013 3:13:42 PM UTC
Be aware that the inheritInChildApplications attribute is not part of the web.config schema (even in VS 2012) so you will get blue squigglies under it with a message of "The 'inheritInChildApplications' attribute is not allowed." It will, however, work correctly.
Craig
Tuesday, March 26, 2013 6:51:44 PM UTC
Scott Lance, Yanesh - True. Things inside are blocked, and things outside are passed down. If you want you can scope some and not scope others on a case by case basis.

Craig - Yes, I'm working on getting it added.
Tuesday, March 26, 2013 7:24:11 PM UTC
I suppose I should fess up. I've mixed .net 4.0 and 2.0 applications in the manner described here. But the unfortunately thing is its not always an option to turn off inheritance in the way you describe (I will admit this is by far the preferred option).

It is still possible to have a .net 2.0 root and have .net 4.0 applications beneath the root (think a Sharepoint 2007 instance with .net 4.0 mvc applications beneath it).

You have to do this however by all sorts of nasty messing around in the root web config and possibly (depending on what you are using) also using assembly redirection in the child.

We had to do this because there is no way to say for just one child to not inherit, you have to say "i'm not inheritable).

krystan honour
Tuesday, March 26, 2013 8:22:44 PM UTC
If I have an "application", it shouldn't inherit from a parent folder in a different "application". That would seem to be the whole point of calling different folders "applications", wouldn't it?

Microsoft totally screwed up here by making folder structure more important than "application" designation.

Also, each app pool should have it's own machine.config for that .NET version.

That would have been the proper way to handle all this. Everything else is just a slimy kludge on top of a bad design.
PRMan
Tuesday, March 26, 2013 8:49:01 PM UTC
Have to agree with PRMan and krystan. Although I appreciate the ability do this, it's never straight forward. It's not as easy as just putting a single location tag in the parent web.config, and it really should be.
Dan H
Wednesday, March 27, 2013 10:22:59 AM UTC
Welcome to the world of constantly checking your web.config to see what mistakes programs make when they edit your web.config automatically.

For example:

- Load IIS
- Click on your website
- Load .NET Error Pages
- Change the setting in here
- Look in your web.config to see what it's done!

In my case it creates a new system.web at the bottom. I've battled with this for over 5 years.

Wednesday, March 27, 2013 12:45:51 PM UTC
Scott,

Is it possible to make main runs in .Net 2.0 Frame work and blog as .Net 4.0 Framework with out using sub web.config ?
Friday, March 29, 2013 10:00:09 AM UTC
hey Mr.Scott I wanna learn Asp.net from you. Will you teach me...Please.
I am a freasher frankly speaking
Chandan Kumar
Friday, March 29, 2013 7:22:25 PM UTC
Nice article. I usually don't comment, But Chandan Kumar made me to! If you want scot to teach you ASP.NET, You should pay him more than what Microsoft does!
johny cage
Friday, March 29, 2013 8:13:44 PM UTC
Hi Scott.
Can you reach Azure team and ask them why they don't let people deploy apps to Azure (ASP.NET Web Site with small SQL Server DB) for free? I find it weird that guys like AppHarbor can do it but MS can't. I think that could convince more people to pay for other Azure services.
AreYouKidding?
Saturday, March 30, 2013 2:50:39 AM UTC
This is really great stuff great article
Saturday, March 30, 2013 7:18:35 AM UTC
Well, "Are you kidding," a 100 meg SQL database is $5 and a 1 GIG SQL database is $9.99, which is pretty cheap.

But for websites like thisdeveloperslife.com, ratchetandthegeek.com and a dozen others I use SQL Compact Edition for free. It's worked great for almost a year.

Does that help?
Monday, April 01, 2013 2:53:36 PM UTC
I haven't used SQL Compact before. Maybe that is an option.
Maybe 5$ isn't much but 60$ a year for app that is built just for fun is not sth I'm ready to pay.
AreYouKidding?
Tuesday, April 02, 2013 6:35:32 PM UTC
AreYouKidding - Remember, you get 10 free websites on Azure. You could make fun sites for free with SQL Compact.
Monday, July 29, 2013 1:43:00 PM UTC
Currently I have some configuration issue with asp.mvc 4 web application deployed under root asp.net webforms 2.0 application (of course this is not best option to work with at all, but it is what it is).
The most interesting part - that application works in the local UAT environment (configured exactly the same as the production) and in one production server, on the second production server it gives an error about wrong configuration (even if the deployed code seems to be exactly the same on both instances. We've been fighting with this issue for some time - but no luck :( .

Honestly speaking - I don't want to introduce changes into root web.config = as new child application is not the only one hosted under same root and it somehow can affect other children (at least there's a chance).
Currently we're going to reinstall app from scratch on the broken server, and I'm willing to introduce changes only into child web.config. In case it's not going to help - I'm simply considering to move away from web application approach (under root item) and have it deployed as standalone web site (just to remove additional dependencies with parent).
alex
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.