Skip to content

Yup, this is by design. Starting in 3.1, authorization attributes are handled by the [authorization middleware](https://github.com/BrightSoul/AuthorizationHandlerMultipleInvocations/blob/master/Startup.cs#L63) instead of being evaluated by MVC's authorization filter. However if you explicitly add an AuthorizationFilter, it would get separately executed. #49900

@tnlthanzeel

Description

@tnlthanzeel
          Yup, this is by design. Starting in 3.1, authorization attributes are handled by the [authorization middleware](https://github.com/BrightSoul/AuthorizationHandlerMultipleInvocations/blob/master/Startup.cs#L63) instead of being evaluated by MVC's authorization filter. However if you explicitly add an `AuthorizationFilter`, it would get separately executed.

Instead of adding a AuthorizationFilter, consider using using RequireAuthorization on an endpoint: e.g.

endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}").
   RequireAuthorization("some_policy");

This would a substitute to adding a global auth filter.

Originally posted by @pranavkm in #32518 (comment)

How to do this to a specific controller in an ASP Core 7 application which has only API contollers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-authIncludes: Authn, Authz, OAuth, OIDC, Bearer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions