I have a controller that runs on ASP.NET Core 1.0 RC2, and I would like to reset the original POST data to telemetry since ApplicationInsights does not do this for you. My code is as follows:
[HttpPost] [Produces("application/json")] public IActionResult Post([FromBody] RequestClass RequestData) { var stream = this.HttpContext.Request.Body; stream.Position = 0; using (var reader = new StreamReader(stream)) { string body = reader.ReadToEnd(); Telemetry.TrackTrace(body, Microsoft.ApplicationInsights.DataContracts.SeverityLevel.Information); } return Ok(); }
But the line "body" always appears empty. If I remove the [FromBody] decor from the function signature, then this code works, but the RequestData object contains only zero, which I don't want.
The only thing I can think of is converting RequestData back to a Json string, but it seems awkward and slow.
(EDIT: POST data - Json)
source share