Asp.net core aspnetcore blazor从razor组件到razor页面的导航
我正在尝试从razor组件重定向到razor页面。若用户未经授权,我想从当前razor组件重定向到登录razor页面 我已重定向到登录组件Asp.net core aspnetcore blazor从razor组件到razor页面的导航,asp.net-core,asp.net-identity,razor-pages,blazor-server-side,Asp.net Core,Asp.net Identity,Razor Pages,Blazor Server Side,我正在尝试从razor组件重定向到razor页面。若用户未经授权,我想从当前razor组件重定向到登录razor页面 我已重定向到登录组件 public class RedirectToLogin : ComponentBase { [Inject] protected NavigationManager NavigationManager { get; set; } protected override void OnInitializ
public class RedirectToLogin : ComponentBase
{
[Inject]
protected NavigationManager NavigationManager { get; set; }
protected override void OnInitialized()
{
NavigationManager.NavigateTo("./Identity/Account/Login",true);
}
}
此行抛出一个错误NavigationManager.NavigateTo(“./Identity/Account/Login”)强>
Microsoft.AspNetCore.Components.NavigationException:“引发了类型为“Microsoft.AspNetCore.Components.NavigationException”的异常。”
我假设问题是从razor组件路由到razor页面。我使用下面的路由器重定向到未授权页面
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<div class="container">
<h1>Sorry</h1>
<p>You're not authorized to reach this page.</p>
<p>You may need to log in as a different user.</p>
<a href="Identity/Account/Login">Log in</a>
</div>
@*<RedirectToLogin />*@
</NotAuthorized>
<Authorizing>
<div class="container">
<h1>Authentication in progress</h1>
<p>Leave your hands on the keyboard, scanning your fingerprints. Ain't technology grand.</p>
</div>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>
@**@
正在进行身份验证
把手放在键盘上,扫描指纹。这不是什么伟大的科技
对不起,这个地址什么也没有
这就足够了。我也有同样的例外。你是如何解决这个错误的?@cickness给出了我们接受的解决方案的答案。