Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you prevent the IIS default site web.config file being inherited by virtual directories?

I have the following code in a web.config file of the default IIS site.

<httpModules>
    <add type="MDL.BexWebControls.Charts.ChartStreamHandler,Charts" name="ChartStreamHandler"/>
</httpModules>

Then when I setup and browse to a virtual directory I get this error

Could not load file or assembly 'Charts' or one of its dependencies. The system cannot find the file specified.

The virtual directory is inheriting the modules from the default web.config.

How do you stop this inheritance?

like image 674
John Owen Avatar asked Sep 01 '08 11:09

John Owen


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.

What are virtual directories in IIS?

A virtual directory is a directory name (also referred to as path) that you specify in Internet Information Services (IIS) 7 and map to a physical directory on a local or remote server.


2 Answers

I've found the answer. Wrap the HttpModule section in location tags and set the inheritInChildApplications attribute to false.

<location path="." inheritInChildApplications="false">
  <system.web>
    <httpModules>
      <add type="MDL.BexWebControls.Charts.ChartStreamHandler,Charts" name="ChartStreamHandler"/>
    </httpModules>
  </system.web>
</location>

Now any virtual directories will not inherit the settings in this location section.

@GateKiller This isn't another website, its a virtual directory so inheritance does occur.

@petrich I've had hit and miss results using <remove />. I have to remember to add it to every virtual directory which is a pain.

like image 101
John Owen Avatar answered Sep 23 '22 03:09

John Owen


Add the following to the virtual directory's web.config file:

<httpModules>
    <remove name="ChartStreamHandler"/>
</httpModules>
like image 43
rpetrich Avatar answered Sep 21 '22 03:09

rpetrich