Wei
Wei

Reputation: 422

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
}

Upvotes: 5

Views: 5371

Answers (1)

Pankaj Bodani
Pankaj Bodani

Reputation: 303

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

Upvotes: 1

Related Questions