Reputation: 2890
I need to limit an access to methods of controller by http method and route template. how to get a template of route from 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();
}
}
}
Upvotes: 2
Views: 1162
Reputation: 2890
I`ve resolve this problem.
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();
}
}
}
Upvotes: 3