Forum Discussion
AllowAnonymous attribute not working
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.