I’m encountering an issue with .NET 8 and Blazor. The interactive render mode is set to Auto (Server and WebAssembly). The problem arises when I add NotAuthorized
and NotFound
; it fails to navigate to either my Login page or my NotFound page. Adding UseStatusCodePagesWithRedirects
allows me to navigate to one of the pages, but I require unauthorized requests to redirect to the login page and requests for non-existing pages to redirect to NotFound.
If the page doesn’t exist, it will simply display the default browser error “page not found.” However, if the page does exist and I’m not logged in, it will navigate to “account/login” instead of “/login,” which is the path of my Login component.
Do you have any ideas on how to achieve this? I’ve searched the internet but couldn’t find a comprehensive solution to my problem.
@using HTPB.Client.Pages
@using Microsoft.AspNetCore.Components.Authorization
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
<NotAuthorized>
<Login></Login>
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<NotFound></NotFound>
</NotFound>
</Router>
</CascadingAuthenticationState>