blazornavigationblazor-server-side.net-9.0

Navigate to fails for standard authentication pages, but not for other pages


To test a problem I'm having, I have set up fresh a .NET 9 Blazor web app (server, global) with individual accounts. I added 2 pages to Pages, Page1 and Page2.

On Page1, I set up 2 buttons, one uses NavigationManager.NavigateTo to navigate to Page2, and the other to the login page (/Account/Login).

Navigating to Page2 works as expected, but navigating to the login page ends on the "Not Found" page.

I also tested this with some of the other pages that come with the project, same result.

When using the URL of the login page directly in the browser everything works fine.

How to fix it?


Solution

  • Found the reason why this happens to the Authencation Pages. These pages aren't Blazor pages, but MVC Razor pages.and live outside the Blazor routing system.

    Fix: use the following code to navigate to these pages:

    NavigationManager.NavigateTo("/Account/Login", forceLoad: true);