"Hooks" in MVC3
本文关键字:quot MVC3 Hooks in | 更新日期: 2023-09-27 17:53:37
我正在使用c#进行MVC3项目,我想知道MVC3是否在CodeIgniter中有类似的钩子(用于在每个ActionResult执行之前执行代码)。我需要它来更新会话中访问过的网站的数组列表。
编辑:我已经想出了一个使用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());
}
你要找的是ActionFilters
你应该使用ActionFilters。这正是你需要的