【发布时间】:2021-05-06 10:47:38
【问题描述】:
我有一个服务器端应用程序,它重定向到另一个应用程序进行登录和注册。所以在app.razor 我做到了:
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
<Authorizing>
<p>Please wait...</p>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
还有重定向组件:
public class RedirectToLogin : ComponentBase
{
protected override void OnInitialized()
{
base.OnInitialized();
//here navigateto....
}
}
这部分可行,因为我确实被重定向了,但是,最初显示的是默认主页。
是否可以更改此行为,以便在加载/显示主页之前发生重定向?
【问题讨论】:
-
我假设您所指的默认页面使用的是
MainLayout。将其更改为不同的布局(您的登录页面正在使用的布局)将解决此问题。 -
@SuprabhatBiswal 登录页面在单独的应用中
标签: asp.net-core blazor blazor-server-side