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.