[英]Fire OnActionExecuted even if response is returned from OnActionExecuting
I have following ActionFilter
attributes implemented for web apis: 我为Web API实现了以下ActionFilter
属性:
LogRequest
: This logs the request and response in OnActionExecuted
method. LogRequest
:这将请求和响应记录在OnActionExecuted
方法中。
ValidateModel
: This validates the model and returns BadRequest
by setting Response
in OnActionExecuting` method. ValidateModel
:这通过在OnActionExecuting方法中设置Response
来验证模型并返回BadRequest
。
Now the problem is that - requests for which we have returned BadRequest
(from ValidateModel
attribute) are not being logged because OnActionExecuted
(of LogRequest
attribute) is not getting fired. 现在的问题是-我们返回的BadRequest
(来自ValidateModel
属性)的请求没有被记录,因为( LogRequest
属性的) OnActionExecuted
没有被触发。
Is there any way I can fire OnActionExecuted
intentionally? 有什么方法可以故意触发OnActionExecuted
吗?
Don't think so. 不要这样 Some options: 一些选项:
- depending on your requirements you could implement a message handler for logging purposes. -根据您的要求,您可以实现消息处理程序以进行日志记录。
- don't execute action logic if you model state is not valid and return BadRequest in OnActionExecuted after logging. -如果模型状态无效,则不要执行动作逻辑,并在记录后在OnActionExecuted中返回BadRequest。
- implement a logging function and just call it whereever you need it. -实现日志记录功能,并在需要时调用它。
... ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.