我正在尝试从剃刀组件重定向到剃刀页面。如果用户未被授权,我想从当前的剃刀组件重定向到Login Razor Page。
我已重定向到登录组件
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类型的异常。'
我得出的假设是问题是从剃须刀组件路由到剃须刀页面。
答案 0 :(得分:0)
我使用下面的路由器重定向到未经授权的页面。
<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>
目前该应用已足够。