Dragos Niamtu
Dragos Niamtu

Reputation: 153

Asp.Net Core 1.1 The key was not found in the key ring

DEFAULT PROJECT IN VS 2017 I have created a new Asp.net Core web application in vs 2017 community and published it on a FTP hosting, but when I submit a form (login or user creation) I get this error:

Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery[7] An exception was thrown while deserializing the token. System.InvalidOperationException: The antiforgery token could not be decrypted. ---> System.Security.Cryptography.CryptographicException: The key {...} was not found in the key ring.

What do I need to do to make it work? thanks.

Upvotes: 15

Views: 21485

Answers (3)

Walter Verhoeven
Walter Verhoeven

Reputation: 4431

Likely your issue is that you have disabled disable the user profile in IIS

Application pool, up date that and the error like

[WRN] Error unprotecting the session cookie.
System.Security.Cryptography.CryptographicException: The key {e47d051f-d492-4df7-8781-31d884833ec6} was not found in the key ring.

and Antiforgery

[ERR] An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
 ---> System.Security.Cryptography.CryptographicException: The key {e47d051f-d492-4df7-8781-31d884833ec6} was not found in the key ring.

Will most likely magically go away.

Upvotes: 6

Ahmed
Ahmed

Reputation: 158

If your hosting environment is using more than one instance for the application this may be the cause of the problem. The simplest way to solve this is to scale down to one instance and make maximum number of instances 1.

This is for the side of identity or login API. As your application is making login to an instance. And checking the token with another instance.

Upvotes: -3

Mike Olund
Mike Olund

Reputation: 429

If your IIS Application Pool is set to use ApplicationPoolIdentity, then you need to make sure "Load User Profile" is set to "True" for the IIS Application Pool.

See: https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/default-settings?view=aspnetcore-2.1

  1. If the user profile is available, keys are persisted to the %LOCALAPPDATA%\ASP.NET\DataProtection-Keys folder. If the operating system is Windows, the keys are encrypted at rest using DPAPI.

Upvotes: 15

Related Questions