Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor server upgraded from 8 to 9, NavigationManager.NavigateTo() exception when going from static ssr page to interactive page

I upgraded blazor server 8 project to 9, the identity pages use static ssr mode and have a IdentityRedirectManager class with this method:

[DoesNotReturn]
    public async void RedirectTo(string? uri)
     {
         uri ??= "";
    
         // Prevent open redirects.
         if (!Uri.IsWellFormedUriString(uri, UriKind.Relative))
         {
             uri = navigationManager.ToBaseRelativePath(uri);
         }
    
         // During static rendering, NavigateTo throws a NavigationException which is handled by the framework as a redirect.
         // So as long as this is called from a statically rendered Identity component, the InvalidOperationException is never thrown.
         await Task.Delay(100);
         navigationManager.NavigateTo(uri); // << error here that prevents page navigation
         
         throw new InvalidOperationException($"{nameof(IdentityRedirectManager)} can only be used during static rendering.");
     }

when I login and login page (a static ssr page) wants to redirect to homepage (a page with -new InteractiveServerRenderMode(prerender: false)-), an exception is thrown, and site crashes. I put await Task.Delay(100); before navigationManager.NavigateTo(uri); still it dosn't work.

all layouts and pages that use static ssr mode, are decorated with:

@attribute [ExcludeFromInteractiveRouting]

and the render modes in App.razor is like this:

private IComponentRenderMode PageRenderMode => HttpContext.AcceptsInteractiveRouting() ? new InteractiveServerRenderMode(prerender: false) : null;

while this site works in .net 8, but upgrade to .net 9, gets error.

Is there any way to correct this?

like image 874
mz1378 Avatar asked Oct 24 '25 16:10

mz1378


1 Answers

I just ran into the same issue. It seems to be a bug with visual studio, as if you continue past the exception while debugging it seems to progress as normal.

Some discussion of the issue here:

https://github.com/dotnet/aspnetcore/issues/58967

https://github.com/dotnet/aspnetcore/issues/53996

like image 189
eight1echo Avatar answered Oct 26 '25 06:10

eight1echo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!