简体   繁体   English

即使OnActionExecuting返回了响应,也会触发OnActionExecuted

[英]Fire OnActionExecuted even if response is returned from OnActionExecuting

I have following ActionFilter attributes implemented for web apis: 我为Web API实现了以下ActionFilter属性:

  1. LogRequest : This logs the request and response in OnActionExecuted method. LogRequest :这将请求和响应记录在OnActionExecuted方法中。

  2. 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.

相关问题 OnActionExecuted不会将响应返回给webpi中的客户端 - OnActionExecuted doesn't return response to client in webpi WebAPI 从 OnActionExecuted 临时覆盖 JsonFormatter - WebAPI Temporarily Override JsonFormatter from OnActionExecuted AngularJS - 即使从Web API返回错误响应,$ http错误回调也无法正常工作 - AngularJS - $http error callback not working even though error response returned from the Web API 如何读取和更改响应的主体到覆盖控制器的OnActionExecuted方法 - How to read and change body of Response into overided OnActionExecuted method of Controller 如何从OnActionExecuting操作过滤器返回值 - how to return value from OnActionExecuting action filter 将ActionFilter.OnActionExecuting()中的对象传递给ApiController - Pass an object from ActionFilter.OnActionExecuting() to an ApiController 在WebApi的ActionFilterAttribute的OnActionExecuted方法中修改HttpContent(actionExecutedContext.Response.Content) - Modify HttpContent (actionExecutedContext.Response.Content) in OnActionExecuted method of WebApi's ActionFilterAttribute 如何防止从Controller继承的类的OnActionExecuting中执行动作 - How to prevent action execution in OnActionExecuting of class that is inhereted from the Controller Web Api - 如何直接从OnActionExecuting过滤器停止Web管道 - Web Api - how to stop the web pipeline directly from an OnActionExecuting Filter 为什么不在OnActionExecuting()方法中将ActionContext.Response设置为BadRequest,直接将其返回给调用者? - Why isn't setting the ActionContext.Response to BadRequest in the OnActionExecuting() method returning it straight back to the caller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM