antiforgery issue #152511
Unanswered
jackie3981
asked this question in
General
antiforgery issue
#152511
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Select Topic Area
Question
Body
ASP .NET 8 API
//Program.cs
...
....
This line
var antiforgery = context. RequestServices.GetRequiredService();
Each time the middleware is executed, it generates a new antiforgery token. This new token is then used for validation, but it does not match the header token and the cookie token, which are the same. The reason for this mismatch is that the header token and cookie token are previously stored and have specific values.
When the middleware is called, it executes
var antiforgery = context.RequestServices.GetRequiredService<IAntiforgery>();
,generating a new token that differs from the previous ones. If I check whether these tokens are created and then avoid calling
var antiforgery = context.RequestServices.GetRequiredService<IAntiforgery>();
,it won’t resolve the issue. In fact, this would cause other problems within the application because antiforgery must be initialized. While I recognize that this initialization is the root of my problem, I am unsure how to resolve it
I would be grateful for any help.
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions