Dot Net 8+ NotFound behavior #61169
Labels
area-blazor
Includes: Blazor, Razor Components
design-proposal
This issue represents a design proposal for a different issue, linked in the description
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.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("/"));
The text was updated successfully, but these errors were encountered: