Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent inheritance for web.config file for "configSections"?

I have following in my parent web applications config file

<configuration>
  <configSections>
    <sectionGroup name="testmodule">
      <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
    </sectionGroup>
  </configSections>
</configuration>

i want to prevent child subfolders from inheriting this config section where should i put <location path="." inheritInChildApplications="false">, since config sections should be first child element of configuration file

like image 848
DSharper Avatar asked Oct 27 '10 07:10

DSharper


People also ask

How do I stop inheritance from 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 Web config be hacked?

1) There is always a chance that somehow a hacker manages to read your web. config in one way or another. If a hacker manages to compromise your web server, having your web. config encrypted would at least slow down, if not stop a hacker from gaining access to your database.

How do you create a web config for different environments?

In order to create the web. config transformations, locate the web. config file in the ASP.NET project, and right-click the item in the solution explorer. Notice the menu item “Add Config Transforms”.

What is location path in web config?

The path attribute defines the site or virtual directory that the configuration settings cover. To specify that the settings in the <location> element apply to the default Web site, set the path attribute to Default Web Site .


2 Answers

This has been answered a couple of times on SO, but incorrectly in my opinion.

The docs, are pretty clear (1)(2):

The following example shows how to use this attribute in a configuration file to specify that the settings defined in the location element for the root of a Web site should not be inherited by child applications:

The InheritInChildApplications property applies only to location-specific configuration settings.

To answer your question, this should suffice:

<configuration>
...
<sectionGroup name="testmodule">
    <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
</sectionGroup>
...
<location path="." inheritInChildApplications="false">
    <testModule>
    ....
    </testModule>
</location>

(1) - http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.inheritinchildapplications.aspx

(2) - http://msdn.microsoft.com/en-us/library/ms178692.aspx

like image 175
Nariman Avatar answered Sep 25 '22 22:09

Nariman


Seems to be no solution for this currently, should avoid using conflicting section groups in web.config file.

like image 44
DSharper Avatar answered Sep 22 '22 22:09

DSharper