AuthorizeView & Authorized enbracing into LayoutComponent

Hi all,

How to use properly AuthorizeView into a blazor component that inherits LayoutComponentBase?

The code snippet below does not work to trigger my Identity server login

<AuthorizeView Roles="HR Admin">
      <RadzenLayout class="rz-shadow-3">
              <div class="d-flex align-items-center">
                  <RadzenSidebarToggle Click="@(() => sidebarExpanded = !sidebarExpanded)" />
                  <RadzenLabel Text="Recursos Humanos" />
          <RadzenSidebar @bind-Expanded="@sidebarExpanded">
                  <RadzenPanelMenuItem Text="Fundos de Compensação" Icon="home" Path="@navigationManager?.Uri" />
              <div class="p-2">
               <Footer />

Hi @Alexandre_Seneda,

You can try removing RadzenLayout to see if it makes a difference.I don't think RadzenLAyout can in any way prevent AuthorizeView from working.

Hi @korchev ,

Thanks for the quick feedback,

I just put the Radzen body outside of AuthorizeView as in the image below and so, it works.

Any thoughts on why?

Best regards

Unfortunately I don't know. All I know is that RadzenLayout does is to render its children and does interfere with AuthorizeView. Also I am not sure that AuthorizeView ever redirects to the login. I couldn't find such code in its implementation but I could be wrong. Again try removing all Radzen components and leave just @Body to see if it works.

Using only :


Does not work

I suspected so. You should probably find another way to redirect to the login. Here is how Radzen applications do it:


<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <RedirectToLogin IsAuthenticated="@context.User.Identity.IsAuthenticated" />
        <PageTitle>Not found</PageTitle>
        <LayoutView Layout="@typeof(MainLayout)">
             Not found


@inject NavigationManager NavigationManager

@code {
    public bool IsAuthenticated { get; set; }

    protected override void OnInitialized()
        if (!IsAuthenticated)
            var redirectUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
            if (!string.IsNullOrEmpty(redirectUrl))
                NavigationManager.NavigateTo($"Login?redirectUrl={Uri.EscapeDataString(redirectUrl)}", true);
                NavigationManager.NavigateTo("Login", true);

Thanks, @korchev for all support.