【问题标题】:Default page is displayed before displaying redirected page在显示重定向页面之前显示默认页面
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2021-07-30
    • 1970-01-01
    相关资源
    最近更新 更多