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 ActionResu开发者_JAVA百科lt 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
精彩评论