Skip to content

Using ASP.NET MVC Customed AuthorizeAttribute in ASP.NET Core #2256

@huyjack178

Description

@huyjack178

I have AuthorizeAttribute in my old ASP.NET MVC project like this

    public class CustomAuthAttribute : AuthorizeAttribute
    {
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                base.OnAuthorization(filterContext);
                ...
            
            }
    }

I want to use this attribute in new site that uses ASP.NET Core MVC Controller/Action.
I have tried to configure in Startup.cs like this

     services.AddMvc(options =>
     {
          options.Filters.Add((new CustomAuthAttribute());
     });

But it can not resolve the type IFilterMetadata.
Moreover, I try to use this Attribute in Controller but nothing happens.

    [CustomAuth]
    public class HomeController : Controller

Anyone can help me? Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions