Kyr
Blazor Web Assembly (stand alone) - [Authorize] Attribute not recognising roles straight after login
have a custom
AuthenticationStateProvider
that adds roles to the ClaimsPrincipal in public override async Task<AuthenticationState> GetAuthenticationStateAsync()
As an anonymous user, when I hit a route protected with the [Authorize(Roles="Administrator")]
attribute, the app correctly sends me to login and redirects me back to the protected route after login.
However, when I log in as a user account that has the "Administrator" role, upon landing back on the protected route it tells me that I don't have permission to access that page (i.e. I'm logged in but don't have the correct role).
If I reload the page in the browser, it then recognises that I have the role and lets me in.
In my case, I'm adding the authorize attribute to a whole directory using _Imports.razor
:
Not sure what I'm doing wrong.49 replies
.NET 8 / Blazor Server+WASM / Configuration
3 replies
Properly output caching an API
I have a .Net 8 Web API (controllers) and I want to do the following:
Cache the output of all successful GET requests (2xx status codes)
VaryBy user
VaryBy resource (controller) and endpoint (action)
VaryBy querystring params (normalised order)
When a PUT, POST, PATCH or DELETE on the same resource is successful, clear the GET caches for that controller for the same user
Ideally I'd like this to happen automatically without needing me to write additional code in my controller actions each time.
I thought I could achieve this with the built in output caching and it feels like it should be possible but I'm striking out on the how and looking for some guidance.
1 replies