Forum Discussion
MikeMP
Aug 03, 2026Copper Contributor
AllowAnonymous attribute not working
Hi, I have a .NET Core 10 MVC web app and I want to create views that can be viewed without requiring login. I have tried adding [AllowAnonymous] both to my controller and to individual views, but t...
Jamony
Aug 09, 2026MCT
AllowAnonymous is appropriate on an MVC controller or action, but it has no effect when placed on a Razor view. Your pipeline is also missing authentication middleware. Add app.UseAuthentication() after app.UseRouting() and immediately before app.UseAuthorization(); keep session after authorization and before the mapped endpoints. The relevant section should be: app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseSession();. Then place [AllowAnonymous] on the controller class or the specific public action and browse directly to that action’s route. AllowAnonymous bypasses authorization requirements for that endpoint, although authentication may still identify a signed-in user. If it still redirects, inspect the selected endpoint’s metadata and any custom middleware, global MVC filter, base controller, or rewrite rule that sends anonymous users to /Identity/Account/Login. Also move UseForwardedHeaders near the start of the pipeline, before HTTPS redirection, when running behind a trusted proxy. That ordering is separate from AllowAnonymous but prevents incorrect scheme or client information from influencing redirects.