Get ActionName, ControllerName and AreaName and pass it in ActionFilter Attribute

前端 未结 5 504
星月不相逢
星月不相逢 2021-01-31 08:34

I use a custom AuthorizationFilter like the followings:

public class ActionAuthorizeAttribute : AuthorizeAttribute {

protected override bool AuthorizeCore(Syste         


        
5条回答
  •  时光取名叫无心
    2021-01-31 09:05

    Face the same issue just a moment ago and my solution is:

    1. Define 2 attributes in your ActionAuthorizeAttribute class e.g.

      public string ControllerName {get;set;}
      public string ActionName {get;set;}
      
    2. While annotating your action of the controller specify them e.g.

      [ActionAuthorize(Roles="Admin", ContollerName="ControllerName",ActionName="ActionName")]**
      public ActionResult Disable(int id)
      {
       ...
      }
      

提交回复
热议问题