IActionFilter和IAuthorizationFilter的区别区别、IActionFilter、IAuthorizationFilter

由网友(十七岁少女竟被男老师轮流布置作业)分享简介:我只是想知道,如果有什么区别 IActionFilter 和 IAuthorizationFilter ?I am just wondering if there are any difference between IActionFilter and IAuthorizationFilter ?我认为我们可以实...

我只是想知道,如果有什么区别 IActionFilter IAuthorizationFilter

I am just wondering if there are any difference between IActionFilter and IAuthorizationFilter ?

我认为我们可以实现相同的逻辑下 IActionFilter 大概有 IAuthorizationFilter ...这是真的?

I assume that we can implement the same logic under IActionFilter that probably has IAuthorizationFilter ... Is that true?

谢谢!

推荐答案

随着每个问题,是的,我们可以实现在两个相同的逻辑 IActionFilter IAuthorizationFilter 。但唯一的执行顺序不同。

As per question ,yes we can implement the same logic in both IActionFilter and IAuthorizationFilter. but the only execution order differs.

ASP.NET MVC框架支持四种不同类型的过滤器:

The ASP.NET MVC framework supports four different types of filters:

    Authorization – Implements  IAuthorizationFilter Attribute.
    Action        – Implements IActionFilter Attribute.
    Result        – Implements  IResultFilter Attribute.
    Exception     – Implements  IExceptionFilter Attribute.

注意: 过滤器上面列出的顺序执行的

授权过滤器总是行动之前过滤器和异常过滤器总是在所有其他类型的执行后,执行过滤器

authorization filters are always executed before action filters and exception filters are always executed after every other type of filter.

批准过滤器来实现验证许可为控制器操作。例如,授权滤波器是一个授权滤波器的示例

Authorization filters are used to implement authentication and authorization for controller actions. For example, the Authorize filter is an example of an Authorization filter.

行动过滤器包含之前和一个控制器动作执行后,执行逻辑。您可以使用动作过滤器,例如,修改视图数据的控制器操作的回报。

Action filters contain logic that is executed before and after a controller action executes. You can use an action filter, for instance, to modify the view data that a controller action returns.

结果过滤器包含之前和视图结果被执行后,执行逻辑。例如,您可能要修改视图结果正确之前的观点呈现给浏览器。

Result filters contain logic that is executed before and after a view result is executed. For example, you might want to modify a view result right before the view is rendered to the browser.

异常过滤器过滤器运行的最后一个类型。您可以使用一个异常过滤器来处理由任何控制器操作或控制器操作的结果出现的错误。您也可以使用异常过滤器来记录错误。

Exception filters are the last type of filter to run. You can use an exception filter to handle errors raised by either your controller actions or controller action results. You also can use exception filters to log errors.

每个不同类型的过滤器是在一个特定的顺序执行。如果你想控制,即同一类型的过滤器执行,那么你可以设置一个过滤器的Order属性的顺序。

Each different type of filter is executed in a particular order. If you want to control the order in which filters of the same type are executed then you can set a filter's Order property.

注意: 所有行动的过滤器的基类是 System.Web.Mvc.FilterAttribute 类的。

Note: The base class for all action filters is the System.Web.Mvc.FilterAttribute class.

阅读全文

相关推荐

最新文章