Runtime error when debugging a ASP.NET 2.0 IIS website that is a sub-web of an ASP.NET 4 IIS website

Article ID: 2023222 - View products that this article applies to.
Expand all | Collapse all

Symptoms

If you use Visual Studio 2010 to create an ASP.NET 2.0 web application as a sub-web underneath an a web application that is targeting ASP.NET 4, your ASP.NET 2.0 application will not run. If you attempt to view the sub-web in your browser, it will show the following error:
"Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive."

If you try to debug from within Visual Studio, you will get:
"Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors."

Cause

In ASP.NET, by default a web application will inherit the configuration settings of its parent. In the case of an ASP.NET 2.0 web application that inherits from an ASP.NET 4 web application, the web.config section “<compilation debug="false" targetFramework="4.0" />” inside of <system.web> is inherited into the ASP.NET 2.0 sub-web. Because the ASP.NET 2.0 sub-web is automatically running under an application pool that is targeting .Net Framework 2.0 by Visual Studio, it uses the ASP.NET 2.0 runtime which does not understand the targetFramework attribute.

Resolution

You can choose to have child applications not inherit the targetFramework attribute by placing the following inside of your parent application:

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

Note that this will affect other applications that you expect to inherit these compilation settings.

Alterntiavely, you can:

  • Move your web site into a location in IIS whose parent targets the 2.0 framework
  • Change your parent web to use the 2.0 framework (Note: this may cause other web applications on your machine to stop functioning properly)
  • Target .NET framework 4 in the sub-web (Note: you will be unable to deploy this Web application to any machine without .NET Framework 4 installed)
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 2023222 - Last Review: June 9, 2010 - Revision: 3.0
APPLIES TO
  • Microsoft Visual Studio 2010 Professional
  • Microsoft Visual Studio 2010 Ultimate
  • Microsoft ASP.NET 4
Keywords: 
KB2023222

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com