开发者

"Hooks" in MVC3

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜