使用 inheritInChildApplications 避免子 Web 应用程序中的 web.config 继承 [英] Avoid web.config inheritance in child web application using inheritInChildApplications

查看:38
本文介绍了使用 inheritInChildApplications 避免子 Web 应用程序中的 web.config 继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加

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

我父母的 web.config 有:

<预><代码><配置><configSections></configSections>//10 个左右的自定义配置部分,如 log4net、hibernate、<连接字符串></connectionStrings><应用设置></appSettings><系统诊断></system.diagnostics><system.web><webParts></webParts><会员资格></会员资格><编译></编译></system.web><位置..><system.web></system.web></位置><system.webServer></system.webServer>

我的子 Web 应用程序设置为 IIS 中的应用程序,并且继承自导致问题的父级 web.config.

我应该把它放在哪里

所以它会忽略所有各种 web.config 设置?

解决方案

正如上一个答案的评论者所提到的,您不能简单地添加行...

...就在 下方.相反,您需要包装要禁用继承的各个 web.config 部分.例如:

<位置路径=."inheritInChildApplications="false"><连接字符串></connectionStrings></位置><!-- 为 appSettings 启用继承 --><应用设置></appSettings><!-- 禁用 system.web 部分的继承 --><位置路径=."inheritInChildApplications="false"><system.web><webParts></webParts><会员资格></会员资格><编译></编译></system.web></位置>

虽然 可能适用于某些配置部分,但有些部分需要 指令,还有其他人似乎也不支持.在这些情况下,设置 inheritInChildApplications="false" 可能是合适的.

I am trying to add

<location inheritInChildApplications="false">

to my parent web application's web.config but it doesn't seem to be working.

My parent's web.config has:

<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>

My child web application is setup as an application in IIS, and is inheriting from the parent's web.config which is causing problems.

Where exactly should I place the

<location inheritInChildApplications="false">

so it ignores all the various web.config settings?

解决方案

As the commenters for the previous answer mentioned, you cannot simply add the line...

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

...just below <configuration>. Instead, you need to wrap the individual web.config sections for which you want to disable inheritance. For example:

<!-- 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>

While <clear /> may work for some configuration sections, there are some that instead require a <remove name="..."> directive, and still others don't seem to support either. In these situations, it's probably appropriate to set inheritInChildApplications="false".

这篇关于使用 inheritInChildApplications 避免子 Web 应用程序中的 web.config 继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆