I have a class that inherits from ApiController. It has a Put-method like this:
[PUT(\"user/{UserId}\")]
public HttpResponseMessage Put(string userId, Payme
A very delayed response, but recently I have had the same challenge to overcome.
I have approached that a bit different without having to get the data from the httpContext (can be quite costly for high volume transaction web application).
I created a simple interface and made each Controller implementing it:
public interface IBaseControllerData
{
object Entity { get; set; }
}
I have then set the Controller's Entity property to the Json payload for each post and put action. Finally, I retrieved the Entity data within the ActionFilterAttribute.OnActionExecuted overridden method and serialised it to Json before injecting into MongoDB:
object entity = ((IBaseControllerData)actionExecutedContext.ActionContext.ControllerContext.Controller).Entity;
requestBody = Newtonsoft.Json.JsonConvert.SerializeObject(entity);
Hope that helps !
Cheers