OnActionExecuting / OnActionExecuted in hijacked controllers
Hey folks,
I'm trying to modify the viewmodel after an action in a hijacked controller, but OnActionExecuted (or OnActionExecuting) methods are never reached/fired.
Example of a hijacked controller:
public class PageHomeController : RenderController
{
public PageHomeController(
ILogger<RenderController> logger,
ICompositeViewEngine compositeViewEngine,
IUmbracoContextAccessor umbracoContextAccessor)
: base(logger, compositeViewEngine, umbracoContextAccessor)
{
}
public override IActionResult Index()
{
return CurrentTemplate(CurrentPage);
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
}
}
I have also tried implementing the OnActionExecuting/Executed in a custom RenderController without success.
These are firing/working as expected in a custom controller.
Got the same issue. I haven't been able to get these methods firing, but managed to do a workaround by using a custom action filter:
public internal class ControllerBaseActionAttribute : ActionFilterAttribute {
public override void OnResultExecuting(ResultExecutingContext context)
{
var result = context.Result as ViewResult;
var viewModel = result?.ViewData.Model;
base.OnResultExecuting(context);
}
}
Then, decorate the controller with the custom filter
[ControllerBaseAction]
public class PageHomeController : RenderController
Hopefully someone else can find a solution to get the action methods fired.
OnActionExecuting / OnActionExecuted in hijacked controllers
Hey folks,
I'm trying to modify the viewmodel after an action in a hijacked controller, but OnActionExecuted (or OnActionExecuting) methods are never reached/fired.
Example of a hijacked controller:
I have also tried implementing the OnActionExecuting/Executed in a custom RenderController without success.
These are firing/working as expected in a custom controller.
Got the same issue. I haven't been able to get these methods firing, but managed to do a workaround by using a custom action filter:
Then, decorate the controller with the custom filter
Hopefully someone else can find a solution to get the action methods fired.
In v10.4.0 at least, you can do
is working on a reply...