Using Antiforgery in ASP.NET Core and got error - the antiforgery token could not be decrypted

后端 未结 3 1715
时光取名叫无心
时光取名叫无心 2021-02-02 16:41

My ASP.Net Core MVC application have added Antiforgery middleware like below:

startup.cs

services.AddMvc();
services.Ad         


        
相关标签:
3条回答
  • 2021-02-02 17:27

    What worked for me was using a new user account instead of NETWORK SERVICE as the error message included this:

    System.UnauthorizedAccessException: Access to the path 'C:\Windows\system32\config\systemprofile' is denied.

    0 讨论(0)
  • 2021-02-02 17:32

    I've had this because I started using the application on a localhost port and then was trying to use it in docker with the same port. By then I had cookies that specified the key generated by my machine, so It wouldn't work on docker.

    TL;DR clear your cookies if you ever used that domain/port from other machines.

    0 讨论(0)
  • 2021-02-02 17:38

    I've had exactly that error on a ASP .net core app hosted on a linux container.

    From the docs it would seem if you don't meet certain criteria the keys are only persisted in the process - but that even for me was not working.

    First the error occurred with the default setup.
    I then added specific configuration for the keys on the filesystem:

                services.AddDataProtection()
                    .PersistKeysToFileSystem(new System.IO.DirectoryInfo(@"/var/my-af-keys/"));
    

    This also didn't fix the issue I had to set an application name:

                services.AddDataProtection()
                    .SetApplicationName("fow-customer-portal")
                    .PersistKeysToFileSystem(new System.IO.DirectoryInfo(@"/var/dpkeys/"));
    

    I haven't confirmed but its possible nature of the LXC hosting means .net core cannot persist the identity of the app.

    0 讨论(0)
提交回复
热议问题