I have a scenario where Users can log in directly via URL without Submitting a form on the Static Server Component in the Blazor Server App.
protected override async Task OnInitializedAsync() { try { if (HttpMethods.IsGet(HttpContext.Request.Method)) await HttpContext.SignOutAsync(); if (parameter && condition) { await DirectLogin(); } } catch (Exception ex) { _logger.LogError(message: ex.Message); }}async Task DirectLogin() { try { //Perform some logic here and then SignIn await HttpContext.SignInAsync(principal, new AuthenticationProperties { ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5) }); _navigation.NavigateTo($"/direct/page/{parameter}", true); //Here I get this exception "Microsoft.AspNetCore.Components.NavigationException" } catch (Exception ex) { errorMessage = $ "Error: {ex.Message}"; _logger.LogError(message: ex.Message); }}This login Component is in a Static Server Render mode whereas after the successful SignIn, the User will be redirected to an Interactive Server Component.
But _navigation.NavigateTo is throwing the following exception
Exception of type'Microsoft.AspNetCore.Components.NavigationException' was thrown
I know this is a known issue and folks on Github are suggesting not to catch this exception as it is handled internally.
But apart from that I don't know the real reason why this exception is occurring.