Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I currently have 2 x ASP.NET 3.5 web applications in IIS7 (lets call them WebParent and WebChild).

WebChild is nested within the WebParent listing in IIS7 and is set up as an application (rather than just a virtual directory within WebParent). Both currently use their own (Classic) application pool.

Both WebParent and WebChild have their own fully defined web.config files in their own root directories.

I had assumed that seeing as WebChild is defined as an 'Application' within IIS, that it would not inherit anything from the WebParent configuration file. However, despite this configuration, I am seeing errors related to various elements within the web.config already being defined (which is correct, there are a couple items that are in both config files, but I thought they should be treated completely independently from one another)?

Can anyone please clarify why this might be occurring?

share|improve this question
    
They probably come from the applicationHost.config. – leppie Nov 10 '10 at 11:51

4 Answers 4

up vote 10 down vote accepted

If they are repeated, you'll have to <remove/> then in the child application web.config first, then add back the element you'd like it it's place. This is assuming that you'd like to have a different value. If you don't, then just omit the element. A connection string would be a good example of something that is likely common for all applications - so you only need to specify it in the root.

Example:

    <siteMap defaultProvider="AdminSiteMapProvider" enabled="true">
      <providers>
        <remove name="AdminSiteMapProvider"/>
        <add name="AdminSiteMapProvider" description="Admin SiteMap provider" type="System.Web.XmlSiteMapProvider" siteMapFile="~/App_Data/admin.sitemap" securityTrimmingEnabled="true" />
      </providers>
    </siteMap>
share|improve this answer
3  
I see, so despite the child being defined as an Application in IIS, it's always still going to be aware of the parent's configuration? Is there a general rule as to which items can be 'duplicated' within each web.config and which items will throw up errors (without the 'remove' solution you've given above)? – marcusstarnes Nov 10 '10 at 12:00
1  
Yes, except in cases where you explicitly prevent inheritance, as Saul explained below. I believe if you have the same name on any element you'll get an exception, but you'll have to give it a try/test. – ScottE Nov 10 '10 at 13:24
1  
Thanks for clarifying, Scott. – marcusstarnes Nov 10 '10 at 13:48
    
This still doesn't take care of inherited settings that don't apply to the childApp which means a TON of maintenance. Seems they should have called it something more like "module" because it's running in the context of another app. Looks like the only viable solution is to setup a separate site using sub-domains to provide a proper "app" context. – rainabba Nov 26 '13 at 23:03

The exact solution to your problem will depend on what configuration exception message you are seeing. However, this is a typical problem that can often be solved through use of the inheritInChildApplications attribute on the location element in the web.config for "WebParent". By wrapping the entire system.web section in a location element as follows, you should be able to eliminate the problem you described:

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

With IIS 7, you will also want to wrap the system.WebServer section the same way:

<location path="." inheritInChildApplications="false"> 
  <system.webServer>
    <!-- ... -->
  </system.webServer>
</location>

This solution is based on an excellent blog article that I found here.

share|improve this answer
    
Thanks a lot Saul. That has also really helped. I wasn't aware of that attribute. – marcusstarnes Nov 10 '10 at 13:00
1  
WOW... I didn't know about this location tag. ASP.NET is surprisingly powerful! :D I was getting errors in the child app related to a Role Provider assembly not being included in the bin folder of the child app. After applying this tag, everything works as expected! :D – Leniel Macaferi Mar 15 '12 at 5:44
2  
This feels like a dirty hack because you either have to put it everywhere (should be the default behavior) and add tags that the childApp might not use OR test the childApp and "fix" each issue. That's not an "app" to me because it's not running in its own context but rather more like a module running inside an app. There's got to be a better way to do this without hosting under another site entirely (which seems like the only REAL solution). – rainabba Nov 26 '13 at 23:01
2  
@rainabba - I agree on the dirty hack feeling. I still have not found a more elegant way to enforce the child app to ignore the parent web.config. It's been 3 years, and I've been using this approach as needed (not too often)... it never gets to feel any better :-/ – Saul Dolgin Nov 27 '13 at 2:54
    
It is a good solution. It solved many of my problems with it but stopped at sectionGroup. I didn't found any work around about sectionGroup so finally used IIS Rewrite Module. Wrote about my experience here: [Persian] bit.ly/1egxsHs – afsharm Apr 5 '14 at 6:43

I think the inheritInChildApplications="false" is good for cases where you still want to inherit some part of the configuration from the parent. In cases where you want to completely stop inheritance (as in this case if I'm correct), I'd suggest to use 2 separate application pools for the 2 apps and then apply a not very well documented setting in the applicationHost.config file as I explained in this question “Entry has already been added” - Two Separate App Pools

<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
    <processModel identityType="NetworkService" />
</add>
share|improve this answer

Follow Scott's advise and also ensure that you have right clicked WebChild in IIS and selected Convert to Application.

share|improve this answer
    
The child is already defined as an application within IIS, and as a result, that option is not available. – marcusstarnes Nov 10 '10 at 11:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.