Custom Authorization filter in ASP.NET MVC 5?

后端 未结 4 767
盖世英雄少女心
盖世英雄少女心 2020-12-06 07:49

In ASP.NET MVC 5 we can use [Authorize] attribute to check authorization and limit access to some actions\\pages. I wonder how can I modify this attribu

4条回答
  •  半阙折子戏
    2020-12-06 08:18

    Something like this? Create your own attribute and override the default with your own code.

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

    Then decorate your controllers/actions with [CustomAuthAttribute]

提交回复
热议问题