Asp.net

使用 inheritInChildApplications 避免子 Web 應用程序中的 web.config 繼承

  • April 23, 2009

我正在嘗試添加

<location inheritInChildApplications="false">

到我的父 Web 應用程序的 web.config,但它似乎沒有工作。

我父母web.config有:

<configuration>
   <configSections>
   </configSections>

   // 10 or so custom config sections like log4net, hibernate,

   <connectionStrings>
   </connectionStrings>

   <appSettings>
   </appSettings>

   <system.diagnostics>
   </system.diagnostics>

   <system.web>
        <webParts>
        </webParts>
        <membership>
        </membership>

        <compilation>
        </compilation>
   </system.web>

   <location ..>
   <system.web>
       </system.web>
   </location>

   <system.webServer>
   </system.webServer>

我的子 Web 應用程序設置為 IIS 中的應用程序,並且繼承自web.config導致問題的父應用程序。

我應該把

<location inheritInChildApplications="false">

所以它忽略了所有各種 web.config 設置?

正如前面提到的答案的評論者所說,您不能簡單地添加該行…

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

…就在下面<configuration>。相反,您需要包裝要禁用繼承的各個 web.config 部分。例如:

<!-- disable inheritance for the connectionStrings section -->
<location path="." inheritInChildApplications="false">
  <connectionStrings>
  </connectionStrings>
</location>

<!-- leave inheritance enabled for appSettings -->
<appSettings>
</appSettings>

<!-- disable inheritance for the system.web section -->
<location path="." inheritInChildApplications="false">
  <system.web>
       <webParts>
       </webParts>
       <membership>
       </membership>

       <compilation>
       </compilation>
     </system.web>
</location>

雖然<clear />可能適用於某些配置部分,但有些部分需要<remove name="...">指令,還有一些似乎也不支持。在這些情況下,設置inheritInChildApplications="false".

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