Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop inheriting web.config from parent ASP.NET application in IIS 7.5

We have deployed an ASP.NET Website (App 1) in IIS 7.5. Then under that application create another ASP.NET application (App 2). But in App 2, I don't want to inherit the web.config from App 1.

If I try to do the following in App 1's, web.config:

<location path="." inheritInChildApplications="false"> 
    <configSections> 

    <!-- etc -->

    </configSections>
</location>

it reports the error:

Config Error The configuration section 'configSections' cannot be read because it is missing a section declaration

If I try to do:

<remove name = "system.web.extensions" /> 

it still reports the same error:

like image 215
Farrukh Avatar asked May 31 '11 06:05

Farrukh


People also ask

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.

What is inheritInChildApplications?

The InheritInChildApplications property represents the inheritInChildApplications attribute of a location element in a configuration file.

What does clear do in web config?

You can use the <clear> element to remove all settings from your application that were defined at a higher level in the configuration file hierarchy.

What is ApplicationHost config file?

ApplicationHost. config is the root file of the configuration system when you are using IIS 7 and above. It includes definitions of all sites, applications, virtual directories and application pools, as well as global defaults for the web server settings (similar to machine.


2 Answers

If you can deploy your child application to a separate website (same machine, different port), Application Request Routing may be able to help with this.

The solution is similar to this post. First, install ARR. Then, configure your "child" application on a website that listens on a non-standard port. Next, configure a rewrite rule on the "parent" application's web site that matches the original path to the "child" application. Have this rule forward the request to the newly created website listening on the new port.

I would post an example, but I expect it is fairly straightforward to see how this would work by looking at the post referenced above.

like image 69
David Kreps Avatar answered Oct 03 '22 22:10

David Kreps


This worked for me.

For those who could not get the location path solution working you might have forgotten to close the location elements tag (if you just edited the web.config in a text editor on the server). Here is an example:

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

Notice that configSections and connectionStrings should not be in the location element which is probably the reason the OPs attempt did not work.

like image 33
Soenhay Avatar answered Oct 03 '22 22:10

Soenhay