Can I host a .net 2.0 virtual directory in asp.net 4.0 site?

不羁的心 提交于 2019-12-21 12:26:28

问题


We've had no problems running .NET 4.0 virtual directories in 2.0 web sites, but the opposite way around is giving us some issues. This is understandable, but is there a way to work around this problem? They are running with different application pools... can we have the virtual directory skip the website's web.config and go directly to the machine.config?

We are getting the following error:

Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

Source Error: 

Line 22:   </appSettings>
Line 23:   <system.web>
Line 24:     <compilation debug="true" targetFramework="4.0" />
Line 25:     <customErrors defaultRedirect="url" mode="RemoteOnly">
Line 26:       <error statusCode="404" redirect="~/404.aspx"/>

回答1:


Add the following into your root web.config

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



回答2:


Is it possible to completely negate a "higher" web.config in a subfolder?

In your root web.config:

  <location path="." inheritInChildApplications="false">
    <system.web>      
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  </location>

(Ben got to this first, but I'll leave this answer as it points to a few alternatives)




回答3:


This is a web.config inheritance issue, and you cannot overcome all the issues with the <location> directive.

We were getting similar errors about duplicate configuration directives on one of our apps. After investigation it looks like it's because of this issue.

In brief, our root website is ASP.NET 3.5 (which is 2.0 with specific libraries added), and we have a subapplication that is ASP.NET 4.0.

web.config inheritance causes the ASP.NET 4.0 sub-application to inherit the web.config file of the parent ASP.NET 3.5 application.

However, the ASP.NET 4.0 application's global (or "root") web.config, which resides at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config (depending on your bitness), already contains config sections that are present in the app-specific web.config of a .NET 3.5 app.

The ASP.NET 4.0 app then tries to merge together the root ASP.NET 4.0 web.config, and the parent web.config (the one for an ASP.NET 3.5 app), and runs into duplicates in the <configSections> node.

The <location> directive cannot be used to prevent inheritance of <configSections> entries. The only solution I've been able to find is to remove the configSections from the parent web.config, and then either

  1. Determine that you didn't need them in your root application, or
  2. Upgrade the parent app to ASP.NET 4.0 (so it gains access to the root web.config's configSections)


来源:https://stackoverflow.com/questions/3469732/can-i-host-a-net-2-0-virtual-directory-in-asp-net-4-0-site

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!