Skip to content

NavigationException thrown in Static Server Render #55685

Closed as not planned
Closed as not planned
@mohiyo

Description

@mohiyo

I have a Login Form inside a Blazor Server App which is working fine with built-in functionality.
But now I am trying to solve a problem where I will be allowing Users to log in automatically when they reach from certain URL and with certain parameters, Without submitting a form

I tried this in my Login Component

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 is not working and I am getting this exception

Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown

Originally posted by @mohiyo in #49472 (comment)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions