deploying AntiforgeryToken Error

2019-01-11 22:51发布

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.

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.

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?

5条回答
何必那么认真
3楼-- · 2019-01-11 23:24

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.

查看更多
聊天终结者
4楼-- · 2019-01-11 23:27

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.

查看更多
The star\"
5楼-- · 2019-01-11 23:30

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

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

查看更多
老娘就宠你
6楼-- · 2019-01-11 23:36

In my case this was an issue with the load balancer not having session persistance turned on for the site.

查看更多
登录 后发表回答