.NET 10 Blazor InteractiveServer模式下/Account/Login页面短暂渲染后消失的问题求助
.NET 10 Blazor InteractiveServer模式下/Account/Login页面短暂渲染后消失的问题求助
我正在用ASP.NET Core Identity构建基于.NET 10的Blazor交互式服务器组件(Interactive Server Components)Web应用,碰到了一个非常棘手的问题:
- 访问
/Account/Login时,登录页面会短暂显示出来 - 紧接着页面就闪一下消失,要么被重定向,要么变成空白页/404页面
- 登录表单根本留不住,还没等我点击提交就没影了
而且这个问题只有在应用进入交互式状态后才会触发,如果禁用交互性或者用普通渲染模式,登录页面就能正常使用,完全没毛病。
下面是我的项目配置信息,麻烦大家帮忙看看哪里出问题了:
服务注册代码
builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddIdentityCore<ApplicationUser>() .AddEntityFrameworkStores<NexaPlatformDbContext>() .AddSignInManager() .AddDefaultTokenProviders();
中间件配置
app.UseAuthentication(); app.UseAuthorization(); app.MapRazorComponents<App>() .AddInteractiveServerRenderMode();
登录组件代码
<CascadingAuthenticationState> <Router AppAssembly="@typeof(Program).Assembly"> <Found Context="routeData"> <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> <NotAuthorized> <RedirectToLogin /> </NotAuthorized> </AuthorizeRouteView> </Found> <NotFound> <p>Not found</p> </NotFound> </Router> </CascadingAuthenticationState>
路由配置
<CascadingAuthenticationState> <Router AppAssembly="@typeof(Program).Assembly"> <Found Context="routeData"> <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> <NotAuthorized> <RedirectToLogin /> </NotAuthorized> </AuthorizeRouteView> </Found> <NotFound> <p>Not found</p> </NotFound> </Router> </CascadingAuthenticationState>
已尝试的排查操作
我已经做了这些调试,但问题还是没解决:
- 确认只有一个组件标记了
@page "/Account/Login" - 登录页面已经添加了
[AllowAnonymous]特性 - 移除了
app.MapAdditionalIdentityEndpoints()配置 - 禁用了预渲染(设置
InteractiveServerRenderMode(prerender:false)) - 检查了Cookie和重定向逻辑,看起来都正常
- 直接访问登录端点是可以正常工作的
另外之前还遇到过这个错误:
AmbiguousMatchException: The request matched multiple endpoints
当时是因为存在多个登录路由导致的,现在已经修复了这个异常,但页面闪烁消失的问题依然存在。
实在没辙了,有没有大佬能指点一下该怎么解决这个问题?
备注:内容来源于stack exchange,提问作者Clarence Simukanzye
相关产品推荐
相关产品推荐

