Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get route name from Attribute routing in ASP MVC5

Does anyone know how to get the route name from Attribute routing in a action filter?

For example I have a controller and attribute route like this:

[HttpGet]
[CustomActionAttribute]
[Route("~/index", Name="IndexPage")]
public async Task<ActionResult> Index()
{
    //Controller logic
}

Is it possible to get route name in the CustomActionAttribute?

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    //Get the current route name here
}
like image 362
Wei Avatar asked Nov 10 '22 00:11

Wei


1 Answers

You can extend RouteCollection to achieve this. You can find example code for this here

like image 182
Pankaj Bodani Avatar answered Nov 15 '22 07:11

Pankaj Bodani