Base solution for your next web application
Open Closed

An exception was thrown while deserializing the token after performing Slot Swap (Clustered Deployment) #12345


User avatar
0
ricardo created

*Aspnet Core MVC *Last Version *Azure App Service

Hi,

After changing slots (staging -> Production), users logged into Production are disconnected and the logs show the error below:

spNetCore.Antiforgery.DefaultAntiforgery - 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 {965441a2-128b-4680-922e-aa50c6196f7a} was not found in the key ring. For more information go to https://aka.ms/aspnet/dataprotectionwarning at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) 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)

*we are publishing in a windows environment on azure with 3 allocated instances, Cache Redis, signalr backplane and Hangfire.

I came across this article: https://aspnetzero.com/blog/persist-data-protection-keys-to-database

Is this type of implementation still necessary or is it standard from Zero?

tanks.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricardo

    Sorry for our late reply. Does this happen when you browse the website in incognito mode ? If you are running the app with multiple instances, please read https://docs.aspnetzero.com/aspnet-core-mvc/latest/Clustered-Environment

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ricardo created

    Hi @ismcagdas,

    it also occurs in anonymous mode.

    We followed all the recommendations in https://docs.aspnetzero.com/aspnet-core-mvc/latest/Clustered-Environment

    We have implemented Azure Redis Cache, we are using Hangfire and we have also implemented Azure SignalR.

    but the documentation does not inform if I should implement what is informed in this article https://aspnetzero.com/blog/persist-data-protection-keys-to-database

    or if this is already handled in some way by zero.

    Redis Config:

    SignalR Config:

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ricardo created

    Hi,

    I managed to solve the problem by following this documentation:

    https://aspnetboilerplate.com/Pages/Documents/XSRF-CSRF-Protection https://github.com/aspnetzero/aspnet-zero-core/issues/4121

    It would be interesting if this section of the documentation was included in the documentation that deals with clustered environments.:

    https://docs.aspnetzero.com/aspnet-core-mvc/latest/Clustered-Environment

    tanks Ricardo

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @ricardo

    Thank you for your feedback and suggestion We are glad you solved the problem. It might be useful to add this documentation to the section on clustered environments

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ricardo created

    Hi @oguzhanagir,

    thank you very much.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)