我试图加载我的网站,我得到这个错误消息:

无法识别的属性'targetFramework'。注意,属性名是区分大小写的。

<compilation debug="true" targetFramework="4.0">

该网站在我的本地PC上运行良好,但当我将其加载到主机并试图在线查看时,它无法打开。


当前回答

我正在使用IIS Express,而不是IIS。

问题出在应用程序主机上。配置文件位于:{solution_folder}\.vs\ Config \applicationhost.config。

其中一个应用程序池条目的managedRuntimeVersion值为“v2.0”。我把它改成了“v4.0”,它可以正常工作。

我很确定根本原因是我最近安装的NuGet包之一。

    <system.applicationHost>
       <applicationPools>
          <add name="BadAppPool1" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
       </applicationPools>
    </system.applicationHost>

其他回答

在VS 2010才有。

修正了通过编辑.sln文件并更改TargetFrameworkMoniker值“. net framework,Version%3Dv4.0”分配给它。

我必须注册ASP。Net,以便在Windows Server 2008 R2中进行解决。下面附有命令的屏幕截图

cd /d C:\Windows\Microsoft.NET\Framework\v4.0.30319

iisreset /stop

aspnet_regiis -i

iisreset /start

%systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /[path='%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll'].allowed:True 

%systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /[path='%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll'].allowed:True 

可能是你有自己的MSBUILD proj文件,并且正在使用<AspNetCompiler>任务。在这种情况下,您应该为. net4添加ToolPath。

<AspNetCompiler
    VirtualPath="/MyFacade"
    PhysicalPath="$(MSBuildProjectDirectory)\MyFacade\"
    TargetPath="$(MSBuildProjectDirectory)\Release\MyFacade"
    Updateable="true"
    Force="true"
    Debug="false"
    Clean="true"
    ToolPath="C:\Windows\Microsoft.NET\Framework\v4.0.30319\">      
</AspNetCompiler>

在Visual Studio菜单中:

网站->开始选项->构建选项卡->选择目标框架 下拉框(。NET FrameWork 4)

对于那些在他们的开发PC上没有运行IIS的人来说,这是发生在我身上的事情:我有一个网站,覆盖了来自一个不同网站的文件,这个网站是4,而之前的是3.5。得到这个错误。修复它只是通过改变网站的目录名称,这在开发PC上可以是任何东西,所以没有问题。 以上的方法可能更优雅,但有时候简单的方法也可以,如果你能做到的话,比如你从事的是开发而不是QA或产品部。