Redirect to login show menu before showing login


I have deployed the blazor webpage inside docker and with traefik as proxy.

The problem is that when I go to my web page, first of all shows de menu and then redirect to the login page:

You can check this behaviour click the following url:

How can I solve it?

Thank you very much.

This happens because of the way security works. It checks if the user is logged in and then redirects to the login page. Sometimes this doesn't happen quickly enough and parts of the layout could render. We aren't aware of a solution for that as Blazor starts rendering as soon as there is await code in OnInitializedAsync.

For what is worth I couldn't see it on the provided URL. Here is a recording of my experience:


When I browse to the provided link I can clearly see the whole menu and then it redirect to the login.

See if this can help you in any way

Thank you! I will try this aproach!

All Radzen Blazor applications have a RedirectToLogin component:

@inject NavigationManager UriHelper

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

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

And It is used in App.razor

<Router AppAssembly="typeof(Startup).Assembly">
    <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                    <RedirectToLogin IsAuthenticated="@context.User.Identity.IsAuthenticated" />
        <LayoutView Layout="typeof(MainLayout)">
            <h1>Page not found</h1>
            <p>Sorry, but there's nothing here!</p>

The thread category is set as Radzen.Blazor components so I am not sure if @zarroc is using Radzen or not.

Yes I am using Blazor

Sorry I mean, I am using Radzen (with blazor obviously)

In that case your application already contains the solution suggested in the Stackoverflow question. Sadly we are not aware of a workaround. It seems Blazor just starts rendering the output before finishing the security check - it doesn't block the thread.