Log request in ASP.NET Web Api

I am trying to log all posted data in my WebApi when an exception is thrown. I tried this:

protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
    if (request.Content == null) 
        return await base.SendAsync(request, cancellationToken);

    var Body = await request.Content.ReadAsStringAsync();

    request.Properties["body"] = Body;

    return await base.SendAsync(request, cancellationToken);
}

      

And in my error log method I am getting posted values ​​in Properties["body"]

.

But when users upload the image, I get this when I try to get the files:

This method or property is not supported after calling HttpRequest.GetBufferlessInputStream.
at System.Web.HttpRequest.get_Files ()

How can I keep only published ones data(text)

in this property?

+3
c # asp.net asp.net-web-api


source to share


No one has answered this question yet

Check out similar questions:

1153
How do I get ASP.NET Web API to return JSON instead of XML using Chrome?
818
ASP.NET Web Site or ASP.NET Web Application?
392
WCF vs ASP.NET Web API
372
How to secure ASP.NET Web API
288
How to pass json POST data to Web API method as object?
173
Unauthorized webapi call returning login page, not 401
96
Need to register asp.net webapi 2 request and response body in the database
73
Unable to inject dependencies into ASP.NET Web API Controller using Unity
nine
ASP.NET Web API Incoming Request Logging
0
Read body of POST request in Web API 2



All Articles
Loading...
X
Show
Funny
Dev
Pics