Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get controller and action name in OnActionExecuting?

Is it possible to figure out the currently executing controller/action in OnActionExecuting?

like image 875
loyalflow Avatar asked Aug 30 '13 14:08

loyalflow


People also ask

What is action name and controller name in MVC?

Actions are public methods in an MVC controller, that respond to a URL request. Action Selectors are attributes that can be applied to action methods and are used to influence or control which action method gets invoked in response to a request.

What is ActionExecutingContext?

ActionExecutingContext(ControllerContext, ActionDescriptor, IDictionary<String,Object>) Initializes a new instance of the ActionExecutingContext class by using the specified controller context, action descriptor, and action-method parameters.


1 Answers

You could try the ActionDescriptor of the ActionExecutingContext as follows:

protected override void OnActionExecuting(ActionExecutingContext filterContext) {    string actionName = filterContext.ActionDescriptor.ActionName;    string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName    .....    base.OnActionExecuting(filterContext); } 
like image 108
chridam Avatar answered Sep 23 '22 03:09

chridam