asp.net-mvc 部署 AntiforgeryToken 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15788912/
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
deploying AntiforgeryToken Error
提问by user1656779
I am working on an ASP.NET MVC application on my local machine using the Visual Studio 2012 built in IISExpress. After a significant progress I decided to make it available across the Local network, I created a virtual directory from visual studio. I can log in but when I try to register a new user. I get the error below.
我正在使用内置于 IISExpress 的 Visual Studio 2012 在我的本地机器上处理 ASP.NET MVC 应用程序。在取得重大进展后,我决定在本地网络上提供它,我从 Visual Studio 创建了一个虚拟目录。我可以登录,但是当我尝试注册新用户时。我收到以下错误。
The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.
无法解密防伪令牌。如果此应用程序由 Web 场或群集托管,请确保所有计算机都运行相同版本的 ASP.NET 网页,并且配置指定显式加密和验证密钥。AutoGenerate 不能在集群中使用。
I generated a new machine key from (ASPNET resources) and placed it in my configuration file but is not still working.Can someone suggest a solution?
我从(ASPNET 资源)生成了一个新的机器密钥并将它放在我的配置文件中,但仍然无法工作。有人可以提出解决方案吗?
回答by Louis Rofrano
One thing I noticed is that this error could be caused by having multiple @Html.AntiForgeryToken()pieces of code on the page. I had 2 on my page and once I removed the second one, this error went away.
我注意到的一件事是,此错误可能是由@Html.AntiForgeryToken()页面上的多段代码引起的。我的页面上有 2 个,一旦我删除了第二个,这个错误就消失了。
回答by Erik Schierboom
You should be adding a machine key that is unique to the website/machine combination. It is this machine key that the token generator uses. This means that you should generate a machine key (which you can do here (dead link-beware)and add it to your Web.config file on your machine. You can find more information here: http://msdn.microsoft.com/en-us/library/ff649308.aspx
您应该添加网站/机器组合独有的机器密钥。令牌生成器使用的正是这个机器密钥。这意味着您应该生成一个机器密钥(您可以在此处执行(死链接-注意)并将其添加到您机器上的 Web.config 文件中。您可以在此处找到更多信息:http: //msdn.microsoft.com /en-us/library/ff649308.aspx
You can also do this directly from within IIS: http://blogs.msdn.com/b/amb/archive/2012/07/31/easiest-way-to-generate-machinekey.aspx
您也可以直接从 IIS 中执行此操作:http: //blogs.msdn.com/b/amb/archive/2012/07/31/easiest-way-to-generate-machinekey.aspx
回答by Eugene Ilyushin
There I was able to find the answer http://iamdotnetcrazy.blogspot.ru/2013/08/how-to-solve-anti-forgery-token-could.html
在那里我找到了答案http://iamdotnetcrazy.blogspot.ru/2013/08/how-to-solve-anti-forgery-token-could.html
回答by CountZero
In my case this was an issue with the load balancer not having session persistance turned on for the site.
在我的情况下,这是负载平衡器没有为站点打开会话持久性的问题。
回答by Dev
I was having a page which was using the partial view. Both contained @Html.AntiForgeryToken() and on removing the @Html.AntiForgeryToken() from the partial page, it worked.
我有一个使用局部视图的页面。两者都包含 @Html.AntiForgeryToken() 并且在从部分页面中删除 @Html.AntiForgeryToken() 时,它起作用了。

