我想控制过滤器的运行顺序,这可能吗?
[LogRequestFilterAttribute]
[ApiKeyRequestFilterAttribute]
我总是想先记录请求,然后进行安全检查,这可能吗? Priority属性似乎与全局过滤器之前/之后的执行有关。
谢谢你, 斯蒂芬
答案 0 :(得分: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()
响应的处理都会被短路,并且不会对该请求进行进一步处理。