I have following ActionFilter attributes implemented for web apis:
LogRequest: This logs the request and response inOnActionExecutedmethod.ValidateModel: This validates the model and returnsBadRequestby settingResponsein OnActionExecuting` method.
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.
Is there any way I can fire OnActionExecuted intentionally?
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.
- implement a logging function and just call it whereever you need it.
...