开发者

"Hooks" in MVC3

开发者 https://www.devze.com 2023-03-01 07:48 出处:网络
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

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

精彩评论

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

关注公众号