无法识别的属性'targetFramework'.请注意,属性名称区分大小写

jay*_*t55 7 .net c# asp.net iis razor

我刚刚将一个网站上传到我的服务器.它在本地完美运行,但在我上传后,在线版本显示:

Configuration Error    Description: An error occurred during the
processing of a configuration file required to service this request.
Please review the specific error details below and modify your
configuration file appropriately. 

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

Source Error: 



Line 37:     </buildProviders>
Line 38:     </compilation>
Line 39:     <httpRuntime targetFramework="4.0"
encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 40:     <machineKey compatibilityMode="Framework45" />
Line 41:  </system.web>


 Source File:  D:\HostingSpaces\o\o.com.au\wwwroot\web.config    Line:
39 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.272

根据本网站上的其他答案,因为服务器上的帐户设置为使用.NET Framework 2.0.但是我的情况并非如此,我已经确定它设置为4.0,我甚至尝试过4.0集成.但它仍然显示此错误.

可能是什么导致了这个?我该如何解决?

在此输入图像描述

Lev*_*evi 18

该应用程序正在尝试使用ASP.NET 4.5中的新功能(特别参见<httpRuntime><machineKey>元素),但服务器只有ASP.NET 4.0.从Web.config中删除<httpRuntime><machineKey>元素以解决此问题.

(有趣的事实:该<httpRuntime/targetFramework>属性不存在,直到4.5因此,即使价值说"4.0",因为它不希望看到这个属性的服务器仍然失败.在所有.)


Ham*_*han 9

可以通过转到IIS,单击"应用程序池"并将"版本"设置为4.0(集成)(运行站点的版本)来解决此问题.接受的答案说HttpRunTime/targetFrameWork>直到4.5才存在.这是不正确的.作为参考,这是HttpRuntime V2 Doc.TargetFrameWork是第4版的新功能.

OP问题中的问题是,他将站点的.NET版本设置为4,但在远程服务器上,2.0运行因此错误.在那种情况下,由于他无法控制远程服务器(假设),在本地将.NET版本更改为2.0可以解决问题,而无需摆弄web.config.