Finding the current Action name from an MVC pipeline processor
Sitecore provides two pipeline hooks for tapping into an Action
method at point of execution:
mvc.actionExecuting
mvc.actionExecuted
These follow standard MVC naming conventions – actionExecuting
fires before your Action method executes, and actionExecuted
fires afterwards.
A process hooking into actionExecuting looks something like this:
At this point, it might be useful to get some information about the Action
we’re executing, or the Controller it belongs to. Sitecore allows us to access the MVC ActionDescriptor
and ControllerDescriptor
objects, which contain plenty of information about our Action
and Controller
.
The last line is commented out, as executing the action from within itself may cause the universe to implode. Maybe.
Happy hacking!