Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The antiforgery token could not be decrypted

I have an identity server asp net core project deployed in Azure, i also have two asp net 5 mvc client using my identity server as SSO, and continuously i am getting(save in logs) an exception

The antiforgery token could not be decrypted.

like image 485
Johan Pino Avatar asked Mar 01 '17 21:03

Johan Pino


People also ask

What is the Antiforgery token could not be decrypted?

Error: 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 <machineKey> configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.

What is Antiforgery token?

To help prevent CSRF attacks, ASP.NET MVC uses anti-forgery tokens, also called request verification tokens. The client requests an HTML page that contains a form. The server includes two tokens in the response. One token is sent as a cookie. The other is placed in a hidden form field.

How is Antiforgery token validated?

In ASP.Net Core anti forgery token is automatically added to forms, so you don't need to add @Html. AntiForgeryToken() if you use razor form element or if you use IHtmlHelper. BeginForm and if the form's method isn't GET. And when user submits form this token is verified on server side if validation is enabled.

How does Antiforgery validation work?

Validates that input data from an HTML form field comes from the user who submitted the data. Obsolete. Validates that input data from an HTML form field comes from the user who submitted the data and lets callers specify additional validation details.


1 Answers

We had similar issue today. We were able to resolve by persisting data protection keys to file system.

services.AddDataProtection()
        .PersistKeysToFileSystem(new DirectoryInfo(@"\\UNC-PATH"));
like image 144
Yousuf Avatar answered Nov 23 '22 12:11

Yousuf