我需要通过http方法和路由模板限制对控制器方法的访问。如何从 context var?
获取路径模板public abstract class BaseController : Controller
{
public override void OnActionExecuting(ActionExecutingContext context)
{
string apiKey = context.HttpContext.Request.Headers["key"];
string httpMethod = context.HttpContext.Request.Method.ToUpper();
string routeTemplate = context. ???
if (CheckAccess(apiKey, httpMethod , routeTemplate))
{
context.Result = Forbid();
}
}
}
答案 0 :(得分:2)
我已经解决了这个问题。
public abstract class BaseController : Controller
{
public override void OnActionExecuting(ActionExecutingContext context)
{
string apiKey = context.HttpContext.Request.Headers["key"];
string httpMethod = context.HttpContext.Request.Method.ToUpper();
string routeTemplate =context.ActionDescriptor.AttributeRouteInfo.Template;
if (CheckAccess(apiKey, httpMethod , routeTemplate))
{
context.Result = Forbid();
}
}
}