简体   繁体   中英

Passing a parameter from control to custom Authorization

I am creating a class that derive from AuthorizeAttribute class. I need to pass the parameter in my controller, where I decorate the derive class. How can I achieve that in this situation?

[SampleAuthorization]
public ActionResult GetFileContent(Guid planId)
{
}

 public class PlanAuthorizationAttribute :  AuthorizeAttribute
 {
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        // how can I use my planId to my custom plan authorizaton        

        base.OnAuthorization(filterContext);
    }
}

您可以在authorizationContext.RequestContext.HttpContext找到值,或者如果planId是路由的一部分,您甚至可以在authorizationContext.RequestContext.RouteData找到它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM