我正在使用C#进行MVC3项目开发,想知道MVC3是否有类似于CodeIgniter中的挂钩(在每个ActionResult执行之前执行代码的功能)。 我需要用它来更新会话中已访问网站的ArrayList。
编辑:我已经使用一个ActionResult解决了这个问题,我会在这里发布它作为参考。
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());
}
这将使ActionFilter始终触发。