ExecuteCore()VS OnActionExecuting(ActionExecutingContext filterContext)? [英] ExecuteCore() vs OnActionExecuting(ActionExecutingContext filterContext)?

查看:596
本文介绍了ExecuteCore()VS OnActionExecuting(ActionExecutingContext filterContext)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是好奇,他们的声音相似。什么是ExecuteCore()VS OnActionExecuting(ActionExecutingContext filterContext)?

Just curious, they sound similar. What are the differences between ExecuteCore() vs OnActionExecuting(ActionExecutingContext filterContext)?

在什么情况下会之一比其他更有用?

In what situations would one be more useful over the other?

推荐答案

其实,他们只是不同点MVC的执行管道。

Actually, they're just different points in MVC execution pipeline.


  1. ExecuteCore被称为
    控制器后MvcHandler
    被实例化。通过这一刻MVC
    甚至不知道如何
    控制器将调用其采取行动。
    您可以覆盖标准
    控制器的ExecuteCore来调整
    其整体的执行过程
    点点。

  1. ExecuteCore is called by MvcHandler after controller itself is instantiated. By this moment MVC doesn't even know about how controller will invoke its action. You can override standard Controller's ExecuteCore to tweak its overall execution process a little bit.

OnActionExecuting是一个完全
不同的故事。这期间调用
操作过滤器通过调用
ControllerActionInvoker。由
点MVC已经知道行动
存在,调用它,获得所有
滤波器(通常定义为
属性),并在执行它
总体执行给定的时刻
管道(OnActionExecuting,
OnActionExecuted,OnResultExecuting
等)。

OnActionExecuting is a completely different story. It is called during action filters invocation by ControllerActionInvoker. By that point MVC already knows that action exists, invokes it, obtains all filters (usually defined as attributes) and executes it in a given moment of overall execution pipeline (OnActionExecuting, OnActionExecuted, OnResultExecuting and so on).

这取决于你要决定使用什么扩展点时获得的是什么。

It depends on what exactly you want to achieve when deciding what extension point to use.


  • 在派生覆盖ExecuteCore
    控制器来调整它的普通
    行为(不是真的经常发生的情况
    在正常的应用程序)。

  • 使用过滤器
    执行一些额外的任务
    似乎正交什么acion本身
    是应该做的(通常这是一些
    AOP样的逻辑或涉及到数据库会话/事务管理)。

这篇关于ExecuteCore()VS OnActionExecuting(ActionExecutingContext filterContext)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆