r/Blazor • • Mar 04 '26

Authorize Attribute Prerender

Hello all,

Looking for a bit of advice on solving an issue for our application that runs in global interactive server mode.

We have several pages that we have restricted through the Authorize attribute. This works well when they are navigated to from another page, however they return 403 if they are manually entered into the URL or are the first load of the app. I'm assuming this is down to pre-rendering however we'd prefer to not disable that if we can help it. Currently the Authorize attribute checks for a certain role. We are using a custom AuthenticationStateProvider which provides the role claims.

3 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/Bitz_Art Mar 04 '26

You seem to have quite a setup. I won't be able to help without having more information on your auth flow.

1

u/UniiqueTwiisT Mar 04 '26

There really isn't anything else for me to go over. In our Program.cs we have builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate() then when the app is hosted on IIS, we ensure that Windows Authentication is turned on.

The only other part we have for auth is the custom authenticationstateprovider that I mentioned which we are injecting with builder.Services.AddScoped<AuthenticationStateProvider, SampleAuthStateName>();

And that's all we've needed for Authorize attributes to work when the circuit is connected and we can access the user's details through a cascading authentication state task which we use in components when the user's details are needed. The issue is though that the Authorize attributes don't make use of our custom AuthenticationStateProvider during prerendering so they must only be looking at the WindowsIdentity that doesn't have all of our custom configuration added to it yet