Dot-Net

如何防止 IIS 預設站點 web.config 文件被虛擬目錄繼承?

  • April 22, 2010

我在預設 IIS 站點的 web.config 文件中有以下程式碼。

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

然後,當我設置並瀏覽到虛擬目錄時,出現此錯誤

無法載入文件或程序集“圖表”或其依賴項之一。該系統找不到指定的文件。

虛擬目錄從預設 web.config 繼承模組。

你如何阻止這種繼承?

我找到了答案。將 HttpModule 部分包裝在位置標記中,並將 inheritInChildApplications 屬性設置為 false。

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

現在任何虛擬目錄都不會繼承此位置部分中的設置。

@GateKiller 這不是另一個網站,它是一個虛擬目錄,因此確實會發生繼承。

@petrich 我使用<remove />. 我必須記住將它添加到每個虛擬目錄中,這很痛苦。

引用自:https://stackoverflow.com/questions/37759