C# 无法识别的属性“targetFramework”。请注意,属性名称区分大小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11890565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive
提问by jay_t55
I have just uploaded a website to my server. And it works perfectly locally, but after I uploaded, the online version displays this:
我刚刚上传了一个网站到我的服务器。它在本地运行良好,但我上传后,在线版本显示:
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
According to other answers on this site, its because the account on the server is set to use .NET Framework 2.0. BUT that's not the case with mine, I've made sure that it's set to 4.0 and I've even tried 4.0 Integrated. But it still displays this error.
根据此站点上的其他答案,这是因为服务器上的帐户设置为使用 .NET Framework 2.0。但我的情况并非如此,我已确保将其设置为 4.0,我什至尝试过 4.0 Integrated。但它仍然显示此错误。
What could be causing this? How can I fix it?
什么可能导致这种情况?我该如何解决?


采纳答案by Levi
The application is trying to use features that are new to ASP.NET 4.5 (see in particular the <httpRuntime>and <machineKey>elements), but the server only has ASP.NET 4.0. Remove the <httpRuntime>and <machineKey>elements from Web.config to solve the issue.
该应用程序正在尝试使用 ASP.NET 4.5 的新功能(特别参见<httpRuntime>和<machineKey>元素),但服务器只有 ASP.NET 4.0。从 Web.config 中删除<httpRuntime>和<machineKey>元素以解决问题。
(Fun fact: the <httpRuntime/targetFramework>attribute didn't exist until 4.5. So even though the value says "4.0," the server still fails since it's not expecting to see this attribute at all.)
(有趣的事实:该<httpRuntime/targetFramework>属性不存在,直到4.5因此,即使价值说“4.0”,因为它不希望看到这个属性的服务器仍然失败。在所有。)
回答by Hammad Khan
This issue can be fixed by going to IIS, click Application Pools and set Version to 4.0 (Integrated)(the one that is running the site). The accepted answer says HttpRunTime/targetFrameWork> does not exists until in 4.5. This is incorrect. For reference, this is HttpRuntime V2 Doc. TargetFrameWorkis new to Version 4.
可以通过转到 IIS,单击应用程序池并将版本设置为 4.0(集成)(运行站点的版本)来解决此问题。接受的答案说 HttpRunTime/targetFrameWork> 直到 4.5 才存在。这是不正确的。作为参考,这是HttpRuntime V2 Doc。TargetFrameWork是第 4 版的新增功能。
The problem in the OP question is, he set the .NET version of the site to 4 but on remote server, 2.0 was running hence the error. In that case since he has no control over remote server (assuming), changing .NET version to 2.0 locally would fix the problem, without fiddling with web.config.
OP 问题中的问题是,他将站点的 .NET 版本设置为 4,但在远程服务器上,2.0 正在运行,因此出现错误。在这种情况下,由于他无法控制远程服务器(假设),将 .NET 版本在本地更改为 2.0 将解决问题,而无需摆弄 web.config。
回答by Daniel Hollinrake
In my case this the solution wasn't to do with not having ASP.NET 4 on my servers. My servers are on a load-balancer and the files for the website are on a Distributed File System. I needed to connect to the DFS with a valid user and password. When this was done I no longer saw the error. However, if you are experiencing this problem check the other solutions first. I would say if you see this error, then nine times out of ten it will be the case that the NET Framework is either not on the server, or not specified for the App Pool.
在我的情况下,这个解决方案与我的服务器上没有 ASP.NET 4 无关。我的服务器在负载平衡器上,网站的文件在分布式文件系统上。我需要使用有效的用户和密码连接到 DFS。完成此操作后,我不再看到错误。但是,如果您遇到此问题,请先检查其他解决方案。我会说,如果您看到此错误,那么十分之九的情况是 NET Framework 不在服务器上,或者未为应用程序池指定。
回答by Rosidin Bima
i think you application pool in IIS is not setup correctly, you must set your apllication pool to ASP.NET v4.0.
我认为您在 IIS 中的应用程序池设置不正确,您必须将您的应用程序池设置为 ASP.NET v4.0。
hope this help
希望这有帮助

