you just deal with the request body, so you donβt need to use the OnActionExecutedAsync method, you can just override OnActionExecuting like this,
public override void OnActionExecuting(HttpActionContext actionContext) { var test = (actionContext.Request.Content as ObjectContent).Value.ToString();
Another option available in the WebAPI is the DelegatingHandler . if you want to register only the request body, then override the SendAsync method,
public class ApiLogHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var requestBody = request.Content.ReadAsStringAsync().Result;
If you decide to choose DelegatingHandler , you need to register this handler with Global message handlers .
source share