I'm working on a MVC3 project using C#, I was wondering if MVC3 has something similar to hooks in CodeIgniter (for executing code just before each ActionResult executes). I need it to update an arraylist of visited websites in the session.
EDIT: I've worked out a solution using an ActionResult, I'll post it here for reference.
ActionFilter:
public class HistoryTracker : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// code here
}
}
Global.asax.cs
protected void Application_Start()
{
// ...
GlobalFilters.Filters.Add(new HistoryTracker());
}
This makes the ActionFilter always trigger.
You are looking for ActionFilters.
You should use ActionFilters. This's exactly what you need
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With