❔ AspNetCore.Components.NavigationException
Hey everyone,
I'm currently working on a Blazor project and using Identity for IAM. However, I've designed my own login and signup pages instead of relying on the Identity UI.
To ensure that users are redirected to my custom pages instead of the Identity UI when they're not authenticated, I've developed a simple component (refer to Screenshot_1). This component is then embedded within the NotAuthorized tag in App.razor (take a look at Screenshot_2).
Now, I'm encountering an issue. As soon as I launch the site, even before the UI is rendered, I encounter a NavigationException exception labeled as "Exception_WasThrown" (thanks, Microsoft!). Clicking "continue" leads me to the login screen as expected. However, after creating an account and logging in, instead of taking me to the authenticated UI, it briefly displays the authenticated UI and then reverts back to the login page, triggering the same exception again.
I've been trying to find more information about this exception and the concept of using a custom page in place of the Identity UI, but I'm coming up short. Could anyone offer any insights or advice on this matter? Your help would be greatly appreciated!
3 Replies
So I've looked into this further and it seems you can't use NavigateTo in OnInitialized(), but you can instead use OnAfterRender(). In my case, this stops any exceptions being thrown, yet when I log in I still have the issue of the UI being rendered and then taking me back to the loginpage, which could suggest I'm missing something to mark the user as authorised, therefore falling under the <NotAuthorized> section of App.razor, which I'll now look into and report back on later if I'm stuck
All good, I was trying to call my cookies two different things so it couldn't find them and authenticate me. Whoops!
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.