Open
Description
Discovered by @davidfowl. If you're trying to make a minimal Blazor Static SSR project from scratch (not from the template), you may be surprised to find that you must call app.UseAntiforgery
even if you're only receiving GET requests and don't have any forms in your whole app. If not, trying to visit any @page
component will result in the error:
It's a pretty weird inconsistency that you get this for MapRazorComponents
endpoints, but do not get this for minimal actions that return RazorComponentResult
.
Possible solutions
- We could change
EndpointMiddleware
so that if it's a GET request, it doesn't try to enforce antiforgery checks. TBH I'm not sure why that's not already the case - do we even support supplying an antiforgery token with a GET request? - Or, we could change
RazorComponentEndpointFactory
so that it registers a separate endpoint for GET vs non-GET and the GET endpoint doesn't have theRequireAntiforgeryTokenAttribute
metadata. - Or, we could change
MapRazorComponents
so that it somehow auto-registers the antiforgery middleware (though this is the least good solution, as it continues to couple different parts of the system and doesn't fix the inconsistency)
Activity