开发者

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

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.a开发者_如何学Pythonspx"/>


Add the following into your root web.config

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


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)


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜