MVC3中的"Hooks"

4

我正在使用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始终触发。
2个回答

6

谢谢,我不知道这个名字。这正是我需要的。 - Geoffrey De Vylder

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接