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

This current discrepancy between local dev and prod is affecting the deployment of our application. Is there a reasonable workaround you can suggest, ideally with some code example that applies to this particular case?

I'm using Microsoft auth which automatically handles setting the claims for me, so I'm not exactly sure what you mean by applying transformers.

Related questions

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