2013-04-05 54 views
2

我想控制过滤器的运行顺序,这可能吗?如何订购我的自定义过滤器属性

[LogRequestFilterAttribute] 
[ApiKeyRequestFilterAttribute] 

我总是想先登录请求,然后安全检查,这是可能的吗? Priority属性似乎与全局过滤器之前/之后的执行有关。

谢谢 斯蒂芬

+0

它是ASP.NET MVC?这些是从ActionFilterAttribute(FilterAttribute)提供的自定义过滤器?如果是的话 - 你可以使用Order属性http://msdn.microsoft.com/en-us/library/system.web.mvc.filterattribute.order(v=vs.100).aspx – outcoldman 2013-04-06 01:50:08

+1

不,只是一个平原由ServiceStack超级收费的vanilla asp.net web项目 – 2013-04-06 04:09:34

回答

2

Request and Response filter attributes优先属性,它可以覆盖,让你指定在其上的过滤器被解雇的排序顺序。

这是事件执行第一个过滤器时,从顺序,从ServiceStack的Order of Operations wiki page

... 

    5. Request Filter Attributes with Priority < 0 gets executed 
    6. Then any Global Request Filters get executed 
    7. Followed by Request Filter Attributes with Priority >= 0 
    8. Action Request Filters (New API only) 
    9. Then your Service is executed with the configured IServiceRunner and its 
    OnBeforeExecute, OnAfterExecute and HandleException custom hooks are fired 
    10. Action Response Filters (New API only) 
    11. Followed by Response Filter Attributes with Priority < 0 
    12. Then Global Response Filters 
    13. Followed by Response Filter Attributes with Priority >= 0 

你关闭你的任何滤波器的响应的任何时间,即httpRes.EndServiceStackRequest()响应的处理是短暂的对此请求不做进一步处理。

相关问题