方法ActionFilterAttribute在控制器ActionFilterAttribute之前

时间:2016-06-23 15:08:13

标签: c# asp.net-mvc-4

如何在控制器ActionFilterAttribute

之前运行方法ActionFilterAttribute

示例:

[Transaction(Order = 20)]
public class BaseController : Controller
    {
...
}

public class Test{} : BaseController {

[HttpPost]
        [WorkReportAccountsSettlementCreatedByCompanyDomainEvent]
        public virtual JsonResult Create(CreateStudentsWorkReportsListOverviewFormModel model)
        {
...
}

}

问题是TransactionAttribute始终在WorkReportAccountsSettlementCreatedByCompanyDomainEventAttribute

之前执行

为什么呢?我想要对方......

1 个答案:

答案 0 :(得分:1)

为什么在TransactionAttribute之前执行WorkReportAccountsSettlementCreatedByCompanyDomainEventAttribute是第一个具有较低的顺序。 您可以查看描述所有过滤器顺序的MSDN page

如果您要查看FilterScope枚举,您会看到以下内容:

public enum FilterScope 
{
    First = 0,
    Global = 10,
    Controller = 20,
    Action = 30,
    Last = 100,
}

这意味着即使您设置了Order = 20,它仍然会在Action = 30之前执行。