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 badges2 Answers
Reset to default 2I 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.
本文标签:
版权声明:本文标题:navigation - Blazor server upgraded from 8 to 9, NavigationManager.NavigateTo() exception when going from static ssr page to int 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303007a1931736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论