Asp.net core 默认页面在显示重定向页面之前显示

Asp.net core 默认页面在显示重定向页面之前显示,asp.net-core,blazor,blazor-server-side,Asp.net Core,Blazor,Blazor Server Side,我有一个服务器端应用程序,可以重定向到另一个应用程序进行登录和注册。所以在app.razor中我做了: <CascadingAuthenticationState> <Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true"> <Found Context="routeData">

我有一个服务器端应用程序,可以重定向到另一个应用程序进行登录和注册。所以在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>
这在一定程度上是有效的,因为我确实被重定向了,但是,默认主页最初是显示的


是否可以更改此行为,以便在加载/显示主页之前发生重定向?

我认为您需要编辑mainlayout.razor页面并在那里添加控件RedirectToLogin,因为Blazor有一个defualt RedirectToLogin.razor控件,该控件也将重定向到defualt Authentication.razor。请检查此

我假设您所指的默认页面使用的是
MainLayout
。将其更改为不同的布局(您的登录页面正在使用的布局)将解决此问题。@SuprabhatBiswal登录页面位于单独的应用程序中
public class RedirectToLogin : ComponentBase
{
    protected override void OnInitialized()
    {
        base.OnInitialized();
        //here navigateto....
    }
}