Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested ASP.NET 'application' within IIS inheriting parent config values?

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?

like image 805
marcusstarnes Avatar asked Nov 10 '10 11:11

marcusstarnes


People also ask

Does web config override IIS settings?

Session timeout: web. config will override the session timeout setting of the IIS config tool Only for ASP.NET apps...

How do I stop inheriting parent web config?

In order to prevent root settings to be inherited, use inheritInChildApplications attribute in location tag. The location path in the example above is empty. It means that this setting will be applied to the level of the config file and below it.

Can we add web config in asp net core?

The web. config file has also been replaced in ASP.NET Core. Configuration itself can now be configured, as part of the application startup procedure described in Startup.


2 Answers

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.

like image 171
Saul Dolgin Avatar answered Sep 19 '22 03:09

Saul Dolgin


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> 
like image 22
ScottE Avatar answered Sep 19 '22 03:09

ScottE