I have a Web API application that I need to get ahold of the return value of some of the API endpoints via an ActionFilter's OnActionExecuted method
I'm using a custom attribute to identify the endpoints that have data that I need to modify, but I can't seem to find the actual result object from within the HttpActionExecutedContext.
Thanks for any help!
Web API includes filters to add extra logic before or after action method executes. Filters can be used to provide cross-cutting features such as logging, exception handling, performance measurement, authentication and authorization.
You can get the returned value through the Response.Content
property. If your action has returned an object you can cast it to ObjectContent
from where you can get the actual instance of the returned value:
public class MyFilterAttribute : ActionFilterAttribute { public override void OnActionExecuted(HttpActionExecutedContext context) { var objectContent = context.Response.Content as ObjectContent; if (objectContent != null) { var type = objectContent.ObjectType; //type of the returned object var value = objectContent.Value; //holding the returned value } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With