admin管理员组

文章数量:1122846

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 8, but upgrade to 9, gets error.

Is there any way to correct this?

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?

Share Improve this question edited Dec 2, 2024 at 6:52 Zhi Lv 21.2k1 gold badge26 silver badges36 bronze badges asked Nov 22, 2024 at 14:51 mz1378mz1378 2,5827 gold badges30 silver badges48 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

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

Finally it worked, in the LoginDisplay the currenturl was:

currentUrl = uriHelper.ToBaseRelativePath(uriHelper.Uri)

I changed it to:

currentUrl = System.Web.HttpUtility
    .UrlEncode($"/{uriHelper.ToBaseRelativePath(uriHelper.Uri)}");

The beggining slash $$"/{..}", helped to resolve the issue.

本文标签: