动作过滤器执行顺序

问题描述:

我创建了两个实现AuthorizeAttribute的类.

I have created two classes that implement AuthorizeAttribute.

一个全局使用,我在Global.asax.cs上设置它:

One is used globally, and I set it on the Global.asax.cs:

filters.Add(new FirstAuthorizeAttribute() { Order = 0 });

另一个称为SecondAuthorizeAttribute,它仅在某些操作方法中使用,我将其用作所需方法中的属性.

The other is called SecondAuthorizeAttribute and it is used only in some action methods, and I use it as attribute in the methods I want.

    [HttpGet]
    [SecondAuthorize]
    public ActionResult LogOut()
    {
        FormsAuthentication.SignOut();
        Session.Clear();
        Session.Abandon();
        return Redirect(Url.Content("~/"));
    }

问题是SecondAuthorizeAttribute总是在FirstAuthorizeAttribute之前执行,而我需要先执行.该命令没有帮助,我该怎么办?

The problem is that SecondAuthorizeAttribute always execute before FirstAuthorizeAttribute, and I need this one to execute first. The order is not being helpful, how could I do it?

这是一个很长的尝试,但是您是否尝试对FirstAuthorizeAttribute使用Global和First值?

This is a long shot, but have you tried using the Global and First values for your FirstAuthorizeAttribute ?

http://msdn.microsoft. com/en-us/library/system.web.mvc.filterscope(v = vs.98).aspx

http://blog.rajsoftware.com/post/2011/05/14/MVC3-Filter-Ordering.aspx