The anti-forgery token could not be decrypted

前端 未结 11 1217
萌比男神i
萌比男神i 2020-11-28 08:34

I have a form:

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary()...

and a

相关标签:
11条回答
  • 2020-11-28 09:07

    My fix for this was to get the cookie and token values like this:

    AntiForgery.GetTokens(null, out var cookieToken, out var formToken);
    
    0 讨论(0)
  • 2020-11-28 09:08

    Just generate <machineKey .../> tag from a link for your framework version and insert into <system.web><system.web/> in Web.config if it does not exist.

    Hope this helps.

    0 讨论(0)
  • 2020-11-28 09:08

    I get this error when the page is old ('stale'). A refresh of the token via a page reload resolves my problem. There seems to be some timeout period.

    0 讨论(0)
  • 2020-11-28 09:09

    you are calling more than one the @Html.AntiForgeryToken() in your view

    0 讨论(0)
  • 2020-11-28 09:14

    I got this error on .NET Core 2.1. I fixed it by adding the Data Protection service in Startup:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDataProtection();
        ....
    }
    
    0 讨论(0)
提交回复
热议问题