0

I am working on a small .Net 5 core project that is hosted on IIS and we not using anti-forgery validation anywhere, In the production server we are getting this error multiples time but not in the local server.

exception was thrown while deserializing the token. Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.

Error does not depend on restart server it comes maybe ramdomly.

Full Error :

2022-04-14 09:51:25.616 +01:00 [Error] 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 {7fd38984-917b-4ace-bdc7-886d65181c3a} was not found in the key ring.
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)
Shivam Mishra
  • 319
  • 3
  • 15
  • Actually we can't do much things only based on the error message, I'm afraid you can refer to [this question](https://stackoverflow.com/q/23402210) to check if any one of the answers can help you. – Tiny Wang Apr 25 '22 at 07:07
  • Hi @TinyWang in that problem user used AntiForgeryToken in the application but in my case we haven't used this. – Shivam Mishra Apr 25 '22 at 07:15
  • yes sir, I noticed it, but actually the error message indicated you used antiforgery token, we can only troubleshoot alone with the error message. We don't know how you write your code nor how you configured IIS. Maybe you can try to publish your app to another environment? Or restart your IIS identity pool? – Tiny Wang Apr 25 '22 at 08:16

0 Answers0