2

我想控制过滤器的运行顺序,这可能吗?

[LogRequestFilterAttribute]
[ApiKeyRequestFilterAttribute]

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

谢谢你,斯蒂芬

4

1 回答 1

2

Request 和 Response 过滤器属性有一个Priority属性,您可以覆盖该属性,让您指定触发过滤器的排序顺序。

这是执行第一个过滤器时的事件序列,来自 ServiceStack 的Order of Operations wiki 页面

  ...

  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()响应的处理是短路的,并且不会对该请求进行进一步的处理。

于 2013-04-06T02:38:41.463 回答