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

前端 未结 5 494
星月不相逢
星月不相逢 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:14

    You could fetch them from the RouteData:

    protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
    {
        var rd = httpContext.Request.RequestContext.RouteData;
        string currentAction = rd.GetRequiredString("action");
        string currentController = rd.GetRequiredString("controller");
        string currentArea = rd.Values["area"] as string;
    
        ...
    
    }
    

提交回复
热议问题