Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 919
Dragos Niamtu Avatar asked Jun 17 '17 08:06

Dragos Niamtu


Video Answer


2 Answers

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://docs.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.
like image 135
Mike Olund Avatar answered Sep 18 '22 21:09

Mike Olund


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.

like image 24
Walter Verhoeven Avatar answered Sep 17 '22 21:09

Walter Verhoeven