Skip to content

UseStatusCodePagesWithReExecute with Blazor not working #56893

@donnykwitty

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

  • .NET 8 Blazor Web App Interactive Server Rendering
  • Start with the standard template
  • create a custom 404 page
  • to program.cs, add app.UseStatusCodePagesWithReExecute("/404");

If this line is placed somewhere before app.UseStaticFiles(); then the content in "NotFound" element of the "Router" element is displayed --- not my custom 404 page.

If the line is placed somewhere after ap.UseStaticFiles() then you get this error:

InvalidOperationException: Endpoint /404 (/404) contains anti-forgery metadata, but a middleware was not found that supports anti-forgery.
Configure your application startup by adding app.UseAntiforgery() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAntiforgery() must go between them. Calls to app.UseAntiforgery() must be placed after calls to app.UseAuthentication() and app.UseAuthorization().

Anti-forgery is already configured, though.

Expected Behavior

I expect my custom 404 page to be displayed (along with a 404 status code being returned tot he client) when using UseStatusCodePagesWithReExecute

Steps To Reproduce

  • .NET 8 Blazor Web App Interactive Server Rendering
  • Start with the standard template
  • create a custom 404 page
  • to program.cs, add app.UseStatusCodePagesWithReExecute("/404");

Exceptions (if any)

InvalidOperationException: Endpoint /404 (/404) contains anti-forgery metadata, but a middleware was not found that supports anti-forgery.
Configure your application startup by adding app.UseAntiforgery() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAntiforgery() must go between them. Calls to app.UseAntiforgery() must be placed after calls to app.UseAuthentication() and app.UseAuthorization().

.NET Version

8

Anything else?

Visual Studio 2022

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions