Compartir a través de


在和子应用程序版本不一致时修改ASP.NET web.config配置文件中的继承权

[原文发表地址] Changing ASP.NET web.config inheritance when mixing versions of child applications

[原文发表时间] 2013-03-26

我的博客和所有相关站点是混用.NET 2.0、3.5和4的。现在这个博客引擎https://hanselman.com/blog 用的是.net 3.5,

但是应用程序所在的根目录https://hanselman.com/ 用的是.NET4。 你可以很愉快的在一个IIS实例中跨.NET版本混用应用程序。

从旁边的截图你可以看到我怎么做的。image_3

可是,当我让子/博客用.NET3.5(2.0 CLR),然后把父/应用程序改成.NET 4的时候,爆出了一大堆下面的错误:

Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive. The targetFramework attribute was inherited from the root .NET 4 Web.config file in the Default Web Site root using ASP.NET configuration inheritance and confused the /blog .NET 2 application.

我不想改变博客应用程序的web.config配置文件,只想让它停止继承父应用程序的配置。你可以在一个location标签中包装整个部分,然后告诉标签所标识的子应用程序不要继承。

你所要做的就是改变父 .NET 4 应用程序的web.config配置文件,让它不要向下影响到诸如.NET 2/3.5/博客程序这些子应用程序。就像下面这样:

    1: <location path="." inheritInChildApplications="false">
    2:    <system.web>
    3:     ...your system.web stuff goes here
    4:    </system.web>
    5: </location>

你可以从ASP.NET 4 Breaking Changes文档阅读到这一详细信息。你会仔细阅读这些,是吧? 我选择修改整个System.Web的设置,如果你喜欢,你也可以在前面的部分修改。

希望这些能帮到你!