代码之家  ›  专栏  ›  技术社区  ›  adopilot

Blazor应用程序中是否存在已实现的拒绝访问路径

  •  0
  • adopilot  · 技术社区  · 5 年前

    AccessDeniedPath Blazor应用程序中的功能。 我的应用程序对某些组件使用基于角色的授权方法。例如( @attribute [Authorize(Roles ="Admin")] )
    在我的应用程序中

    <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
        <NotAuthorized>
                <h1>Sorry</h1>
                <p>You're not authorized to reach this page.</p>
                <p>You may need to log in as a different user.</p>
        </NotAuthorized>
        <Authorizing>
            <h1>Authentication in progress</h1>
            <p>Only visible while authentication is in progress.</p>
        </Authorizing>
    </AuthorizeRouteView>
    

    NotAuthorized 无论是来自没有权限的用户还是匿名用户(根本没有授权)。

    0 回复  |  直到 5 年前
        1
  •  2
  •   itminus    5 年前

    有一个 context

    例如:

    <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" >
        <NotAuthorized>
            @if(!context.User.Identity.IsAuthenticated)
            {
                <p> You need Login! </p>  
            } else{
                <p> Sorry, the content here is not for you! </p> 
                @*or render or component like <AccessDenied /> directly *@
            }
        </NotAuthorized>
        <Authorizing>
            <h1>Authentication in progress</h1>
            <p>Only visible while authentication is in progress.</p>
        </Authorizing>
    </AuthorizeRouteView>