profile
viewpoint

Ask questionsAspNetCore 3.0 Blazor Server inconsistent rendering between server and client of authorized components

I am seeing a weird issue during the runtime of my ASP.NET Core 3.0 Blazor Server app where the prerendered page properly renders HTML inside of an <AuthorizeView Policy="Admin"> but quickly gets updated to render the <NotAuthorized> version once the browser client loads. I've attached a video demo below as well as the relevant source code. You can see the view flicker from the properly authorized view to the unauthorized one, even though the user remains logged in with the appropriate claims.

Demo

Demo

Source

In Startup.cs:

services.AddAuthorization(options =>
{
    options.AddPolicy("Admin", policy =>
    {
        policy.RequireAssertion(context => context.User.HasClaim(c => c.Issuer == "Microsoft"));
    });
});

In NavMenu.razor:

<AuthorizeView Policy="Admin">
    <Authorized>
        <NavLink href="/admin">Admin</NavLink>
    </Authorized>
</AuthorizeView>

In Admin.razor:

@page "/admin"
@attribute [Authorize(Policy = "Admin")]

<h3>Admin</h3>
aspnet/AspNetCore

Answer questions pheuter

I should add that the same exact app works just fine in development. Can this have something to do with the fact that the production app uses Azure SignalR and for some reason that fails to read claims on the user session? Interesting enough, Azure SignalR is still able to tell that my user is logged in.

Edit: I already have sticky mode turned on, doesn't seem to help: options.ServerStickyMode = Microsoft.Azure.SignalR.ServerStickyMode.Required;

Related questions

ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY when clean webapi template hot 255
Restore MvcJsonOptions to ASP.NET Core 3.0 as a type forward? hot 226
HTTP Error 500.31 - ANCM Failed to Find Native Dependencies hot 219
The SPA default page middleware could not return the default page '/index.html' in production application hot 139
HTTP Error 500.30 - ANCM In-Process Start Failure hot 127
Calling Request.EnableRewind throw on 3.0.0-preview7 hot 125
HTTP Error 500.30 - ANCM In-Process Start Failure hot 120
ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY when clean webapi template hot 109
DataProtection - CryptographicException when using EntityFramework as Key Storage Provider hot 93
Issue with BuildServiceProvider() in ConfigureServices() hot 91
Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRounting = false' inside 'ConfigureServices'. hot 89
Error: Server returned handshake error: Handshake was canceled. hot 82
Blazor - rzc generate exited with code 1. DotNet Core 3.0.100-preview8-013656 hot 77
error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' hot 75
IIS in-process hosting incorrectly throws ConnectionResetException for HTTP POST hot 74
Github User Rank List