首页 > 解决方案 > 在 Blazor 应用程序中使用意外名称进行标记?

问题描述

尝试在我的 blazor Web 程序集应用程序中建立用户帐户并构建身份验证元素。

但是,两个组件有错误:

Found markup element with unexpected name 'xxxxxxxxxxxxxxxx'

两个有问题的组件是 AuthorizeRouteView 和 CascadingAuthenticationState。

我的代码:

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
    </Found>
    <NotFound>
        <CascadingAuthenticationState>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </CascadingAuthenticationState>
    </NotFound>
</Router>

任何线索可能是什么问题?

标签: c#authenticationauthorizationblazor

解决方案


尝试以下设置。请注意,NotAuthorized 属性元素中有一个名为 RedirectToLogin 的元素。这是您应该定义的 Razor 组件的名称(RedirectToLogin.razor 文件名),并且可能需要在 _Imports.razor 文件中更新其命名空间(例如:@using OpenIDConnectSample.Shared)。

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" 
                             DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    <RedirectToLogin />
                </NotAuthorized>
                <Authorizing>
                    Wait...
                </Authorizing>
            </AuthorizeRouteView>
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

推荐阅读