ctor
ctor

Reputation: 875

Fire OnActionExecuted even if response is returned from OnActionExecuting

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?

Upvotes: 0

Views: 351

Answers (1)

Ivaylo Stoev
Ivaylo Stoev

Reputation: 487

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

Upvotes: 0

Related Questions