Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Docker Antiforgery token validation failed #5453


User avatar
0
cyklussoftware created

I am running ASP.NET Core + jQuery v5.5.0 with .NET Core 2.1. The project was set up with nothing changed except connection strings (I am testing building / deploying to Docker). I am using Docker Toolbox on Windows Server 2008 R2.

My Dockerfile:

FROM microsoft/dotnet:2.1-aspnetcore-runtime

WORKDIR /app
COPY . .

ENTRYPOINT ["dotnet", "MyCompany.MyApp.Web.Mvc.dll"]

My docker-compose.yml

version: "3"
services:
    mvc:
        image: continuoustestingmvc
        environment:
            - ASPNETCORE_ENVIRONMENT=Staging
        deploy:
            replicas: 5
            restart_policy:
                condition: on-failure
        ports:
            - "9903:80"
        volumes:
            - "/c/Users/aspnetcore_logs/:/app/App_Data/Logs"
        networks:
            - webnet
networks:
    webnet:

I open my web browser and I can connect to the website running in the Docker container. The page loads with no errors. When I click "Change tenant", the user friendly "Error! An internal error occurred during your request!" dialog pops up with a loading indicator. It never goes away.

At the same time, the following error appears in the Logs:

Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted. ---> System.Security.Cryptography.CryptographicException: The key {f38bd4e9-c084-4734-98bf-f029e03bfa32} was not found in the key ring.

When I run the application on my local machine using ASPNETCORE_ENVIRONMENT=Staging and "dotnet MyCompany.MyApp.Web.Mvc.dll", everything works fine. The problem is only in Docker.

I'm not sure where this problem originates from. Is it an issue with the .NET Core 2.1 Docker Image? Or was it fixed in ASP.NET Zero v5.6?


1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    Looks like a problem about Data Protection Keys. See these;

    <a class="postlink" href="http://blog.stoverud.no/posts/asp-net-core-dataprotection-and-azure-web-apps/">http://blog.stoverud.no/posts/asp-net-c ... -web-apps/</a> <a class="postlink" href="https://github.com/aspnet/Mvc/issues/6480#issuecomment-312691214">https://github.com/aspnet/Mvc/issues/64 ... -312691214</a>