0

I have following ActionFilter attributes implemented for web apis:

  1. LogRequest: This logs the request and response in OnActionExecuted method.

  2. ValidateModel: This validates the model and returns BadRequest by setting Response in 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?

ctor
  • 705
  • 7
  • 23

1 Answers1

0

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

Ivaylo Stoev
  • 357
  • 2
  • 7