如何使ActionFilter行动采取的方法precedence超过控制器相同ActionFilter [英] How to make ActionFilter on action method take precedence over same ActionFilter on controller

查看:109
本文介绍了如何使ActionFilter行动采取的方法precedence超过控制器相同ActionFilter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自十一月以来asp.net mvc的有了很大的变化,没有人有解决这个问题:

Since asp.net mvc has changed a lot since November, does anyone have a solution to this question:

<一个href=\"http://stackoverflow.com/questions/274039/resolve-filterattributes-on-controller-and-action\">http://stackoverflow.com/questions/274039/resolve-filterattributes-on-controller-and-action

菲尔说一个控制器上的ActionFilter是用于应用属性到控制器的所有action方法只是简写,它是真实的,如果我把同样的ActionFilter属性控制器和操作方法,它将运行两次。但是,这似乎是理所当然的行为并不因为编译器甚至不会让你直接多次把同样的属性上的方法。

Phil said an ActionFilter on a controller is just shorthand for applying the attribute to all action methods of the controller, and it is true, if I put the same ActionFilter attribute on the controller and on an action method, it will run twice. But this doesn't seem like natural behavior since the compiler won't even let you put the same attribute directly on a method multiple times.

推荐答案

一个过滤器可以通过specifing每个过滤器订单财产采取precedence了另一个过滤器。例如...

A filter can take precedence over another filter by specifing the Order property on each filter. For example...

[MyFilter(Order=2)]
public class MyController : Controller
{
    [MyFilter(Order=1)]
    public ActionResult MyAction()
    {
    	//...
    }
}

在这个例子中的操作方法过滤器将控制器上的文件管理器之前执行。

In this example the filter on the action method would execute before the filer on the controller.

心连心

这篇关于如何使ActionFilter行动采取的方法precedence超过控制器相同ActionFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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