【问题标题】:ASP.NET Web.config <runtime> element not inherited into child applicationASP.NET Web.config <runtime> 元素未继承到子应用程序中
【发布时间】:2015-01-07 19:23:24
【问题描述】:

我有一个作为 IIS 网站创建的 ASP.NET MVC5 应用程序,它有自己的 .NET 4.0 CLR 应用程序池和物理路径:

C:\Websites\XXX\Web\en-HK

在此站点下,我在 IIS 中有一个子应用程序“zh”(另一个 MVC5 应用程序),同样具有自己的 .NET 4.0 CLR 应用程序池和物理路径:

C:\Websites\XXX\Web\zh-Hans-HK

两个站点都有自己的 web.configs,子站点仅覆盖一个正在工作的 &lt;appSetting&gt;。然而,不起作用的是父元素中的元素似乎没有被继承下来。元素看起来像:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

当我第一次在浏览器中运行子应用程序时,我看到一个 YSOD 抱怨找不到 MVC 3.0 - 这是因为第 3 方 DLL 正在寻找 MVC 3,但应该重定向到 5.2 的绑定不是在那里。

如果我将 &lt;runtime&gt; 元素粘贴到子 web.config - 错误就会消失。

&lt;runtime&gt; 元素是否被设计阻止在子应用程序中继承,或者我的设置是否关闭? 它似乎没有在 machine.config 中受到保护。

更新

我认为问题与装配探测有关。

启用程序集加载跟踪后,我可以看到子应用程序中的 YSOD 是由 ELMAH 对 MVC3 的依赖引起的,当 .NET 探测应用程序配置(我的子应用程序 web.config)时,它找不到任何 @ 987654328@ 信息因此继续检查 aspnet.config不是我的父网站 web.config,它确实有 &lt;assemblyBinding&gt; 信息。

我猜这是设计使然?

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc-5 iis-7.5


    【解决方案1】:

    Asp.Net 引擎将您的 Web.config 文件按照 IIS 层次结构组合成最终配置源,.Net 运行时用于特定 Web 位置内的请求

    不过,&lt;runtime&gt; 部分有点特殊,因为它的级别太低了。它不是由托管代码使用,而是由非托管 .Net 运行时 host 使用来定义其整体行为(程序集绑定是最常见但与 GC 相关的东西和其他东西)

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 2010-10-21
      • 2012-10-01
      • 2011-09-05
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2016-03-11
      相关资源
      最近更新 更多