Nick
Nick

Reputation: 1891

anti-forgery token error

I have an mvc2 project built for .NET 3.5. I have a library that I wrote in 4.0 that I need for the 3.5 project, so I changed the target framework and now the anywhere the anti-forgery token it throws:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

I found this question but no luck with any of the suggestions. I created a static machine key in my config but it doesn't help. Anybody have any idea what could be the problem. I don't understand why it worked fine before.

Upvotes: 2

Views: 1931

Answers (1)

Scott Rippey
Scott Rippey

Reputation: 15810

You have to close all browser windows to continue.

The AntiForgeryToken cookie is a session-cookie, and is encrypted / decrypted using the machine key. If the machine key changes (or is set to auto-generate), then rendering the AntiForgeryToken will fail.

Restarting your browser windows will clear the cookie, and MVC will create a new, valid cookie next time.

Upvotes: 4

Related Questions