简体   繁体   English

如何防止IIS默认站点web.config文件被虚拟目录继承?

[英]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. 我在默认IIS站点的web.config文件中包含以下代码。

<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. 虚拟目录从默认的web.config继承模块。

How do you stop this inheritance? 您如何停止这种继承?

I've found the answer. 我找到了答案。 Wrap the HttpModule section in location tags and set the inheritInChildApplications attribute to false. 将HttpModule节包装在位置标记中,然后将InheritedInChildApplications属性设置为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. @GateKiller这不是另一个网站,它是一个虚拟目录,因此会发生继承。

@petrich I've had hit and miss results using <remove /> . @petrich我已经使用<remove />命中和错过了结果。 I have to remember to add it to every virtual directory which is a pain. 我必须记住将其添加到每个虚拟目录中,这很麻烦。

Add the following to the virtual directory's web.config file: 将以下内容添加到虚拟目录的web.config文件中:

<httpModules>
    <remove name="ChartStreamHandler"/>
</httpModules>

According to Microsoft , other websites do not inherit settings from the Default Website. 根据Microsoft的说法 ,其他网站不会从默认网站继承设置。 Do you mean you are editing the default web.config which is located in the same folder as the machine.config? 您是说要编辑默认的web.config,它位于与machine.config相同的文件夹中吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM