asp.net - 使用inheritInChildApplications避免子Web应用程序中的web.config继承

标签 asp.net configuration iis-7 web-config

我正在尝试添加

<location inheritInChildApplications="false">

到我的父 Web 应用程序的 web.config,但它似乎不起作用。

我 parent 的 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" 可能是合适的。 .

关于asp.net - 使用inheritInChildApplications避免子Web应用程序中的web.config继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/782252/

相关文章:

asp.net - IIS7和ASP.NET如何限制用户请求

asp.net-mvc - 使用 https ASP.NET MVC 网站保护所有资源(图像、脚本、页面、sessionCookie),并从 http 重定向到 https

asp.net - IIS中ASP.net应用程序的单独应用程序池

c# - 首先运行 javascript,成功后运行后面的代码

ASP.NET Core 2.1 API 缓存

javascript - Ajax 数据未在下拉列表中正确绑定(bind)

configuration - 如何自定义 CK-Editor 的工具菜单?

c# - .NET 项目在将平台更改为 x64 并返回到任何 CPU 后未构建

c# - "True"REST 路由通过 MVC 4 Web API

php - IIS:.htaccess php_flag/php_value 替代方案?