You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazor中使用RedirectToLogin.razor重定向出现错误求助

Blazor 授权跳转登录页面时出现错误,请求帮助

App.razor 代码

@using DorpshuisManager.Areas.Identity.Components

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(App).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    @if (!context.User.Identity.IsAuthenticated)
                    {
                        <RedirectToLogin ReturnUrl="@NavigationManager.ToBaseRelativePath(NavigationManager.Uri)" />
                    }
                    else
                    {
                        <p role="alert">Sorry, you're not authorized to view this page.</p>
                    }
                </NotAuthorized>
            </AuthorizeRouteView>
            <FocusOnNavigate RouteData="@routeData" Selector="h1" />
        </Found>
        <NotFound>
            <PageTitle>Not found</PageTitle>
            <LayoutView Layout="@typeof(MainLayout)">
                <div class="d-flex vw-100 vh-100 align-items-center justify-content-center text-center">
                    <div>

                        <iconify-icon icon="tabler:face-id-error" style="color: black;" width="100" height="100"></iconify-icon>
                        <h1>Pagina niet gevonden ...</h1>
                        <a href="/">
                            <button class="btn btn-primary mt-3 btn-rounded py-3 px-4">Ga naar home pagina</button>
                        </a>

                    </div>
                </div>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

RedirectToLogin.razor 代码

@code {
    [Parameter]
    public string ReturnUrl { get; set; }

    protected override async Task OnInitializedAsync()
    {
        ReturnUrl = "~/" + ReturnUrl;
        NavigationManager.NavigateTo("Identity/Account/Login?returnUrl=" + ReturnUrl, true);
        await base.OnInitializedAsync();
    }
}

运行代码时出现错误(截图:错误预览)。我已在谷歌、Stack Overflow搜索解决方案,尝试过Blazor组件跳转至Razor页面的相关方案,但均无法解决问题,恳请帮忙排查。

内容的提问来源于stack exchange,提问作者Jeremy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 03:41:30