Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot Net 8+ NotFound behavior #61169

Closed
nw5428 opened this issue Mar 26, 2025 · 4 comments
Closed

Dot Net 8+ NotFound behavior #61169

nw5428 opened this issue Mar 26, 2025 · 4 comments
Labels
area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description

Comments

@nw5428
Copy link

nw5428 commented Mar 26, 2025

This is in reference to #48983

My requirements are to display a user friendly not found page for any path that does not have a specified route and do not redirect which updates the URI. We did not realize that Dot Net 8 changed this behavior.

After trying 18 different things, finally tried adding the below in program.cs between builder.Build and calls to UseAuthentication / UseAuthorization which appears to work perfectly.

app.UseStatusCodePagesWithReExecute("/");

//We do not want reexecute for anything in our api calls
app.Use(async (context, next) =>
{

    if (context.Request.Path.StartsWithSegments("/api", StringComparison.OrdinalIgnoreCase))
    {
        var statusCodeFeature = context.Features.Get<IStatusCodePagesFeature>();

	if (statusCodeFeature != null && statusCodeFeature.Enabled)
	{
		statusCodeFeature.Enabled = false;
	}
    }

    await next();
});

app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), (appBuilder) =>
{
appBuilder.UseProblemDetails();
});

This ends up reverting the behavior to functionally do the same thing it did in .net 7. It will use the in the main blazor router. The other suggestions mentioned are ok but they do not retain the original URL in the browser.

I think the documentation should be updated to notate this option and the feature retained in future releases.

I think it also makes sense to instead have an option that is more obvious such as:

app.MapRazorComponents(options => options.FallbackOnNotFound("/"));

@nw5428 nw5428 added the design-proposal This issue represents a design proposal for a different issue, linked in the description label Mar 26, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 26, 2025
@garrettlondon1
Copy link

garrettlondon1 commented Mar 26, 2025

I believe the documentation was updated, where "NotFound" is no longer used and has to go through standard middleware

@nw5428
Copy link
Author

nw5428 commented Mar 26, 2025

yeah I saw that. I disagree with the assessment and think there should be an easier way to handle it, which I proposed.

@javiercn
Copy link
Member

@nw5428 thanks for contacting us.

We are doing work in this area in .NET 10.0, but we aren't bringing back the fallback endpoint as that causes a whole set of different problems.

Our plan includes supporting a NotFound @page that can be used with UseStatusCodePagesWithReExecute and that also works on interactive scenarios.

@nw5428
Copy link
Author

nw5428 commented Mar 27, 2025

Sounds good. Thanks

@nw5428 nw5428 closed this as completed Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description
Projects
None yet
Development

No branches or pull requests

3 participants