--- lang: ja-jp breaks: true --- # Blazor 認証認可で「A valid antiforgery token was not provided with the request.」エラーが発生した場合の対応 2024-08-08 # エラー内容  ``` A valid antiforgery token was not provided with the request. Add an antiforgery token, or disable antiforgery validation for this endpoint. ``` :::info リクエストで有効なアンチフォージェリ・トークンが提供されていません。アンチフォージェリ・トークンを追加するか、このエンドポイントのアンチフォージェリ検証を無効にしてください。 ::: ## Issues > Blazor antiforgery token issue when posting form (SSR) when user is logged in #50612 > https://github.com/dotnet/aspnetcore/issues/50612 > https://github.com/dotnet/aspnetcore/issues/50612#issuecomment-1722177730 > ## `app.UseAuthorization();` の順番を入れ替えると正常に動作する。 ### `Program.cs` * 以下はエラーとなる ```csharp= app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAntiforgery(); // 認証認可のミドルウェアを追加 app.UseAuthentication(); app.UseAuthorization(); app.MapRazorComponents<App>() .AddInteractiveServerRenderMode() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(Client._Imports).Assembly); ``` * 以下は正常に動作する。 ```csharp= app.UseHttpsRedirection(); // 認証認可のミドルウェアを追加 app.UseAuthentication(); app.UseAuthorization(); app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents<App>() .AddInteractiveServerRenderMode() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(Client._Imports).Assembly); ``` ###### tags: `Blazor` `認証認可` `UseAntiforgery()`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up