Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

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

$
0
0

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?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>