3
votes

How to debug HTTP requests, toward Web Api, that remain Pending without entering Controller?

This is my request

curl "http://localhost:50086/foo/bar" -X OPTIONS -H "Access-Control-Request-Method: POST" -H "Origin: http://localhost:3333" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.116" -H "Access-Control-Request-Headers: content-type,x-auth-token" --compressed

There is nothing in EventLog and Debug console. Those pending requests occur at random time and wont go through before restarting application (in some cases they enter controller but after very long time).

I am using .net Core 2.2

2
People are voting to close your post as too broad, you need to add to your post and make this more specific or it may be closed before you get an answer. Add the code you are using to make these API requests to your post as well as what you mean by they occur at random times.Ryan Wilson
The Event log and debug console don't log HTTP requests. Your web server's log does that. Are you using IIS? Did you check IIS's logs?Panagiotis Kanavos
@Mirhat When I said to post your code for making your API request, I meant to post your C# code for making the request.Ryan Wilson
Take a look at Telerik Fiddler and see if it helps at all.Aaron
@RyanWilson I don't see how that will help. Requests are working fine until this situation happens.Mirhat

2 Answers

5
votes

you can use Middleware for this.

public class RequestDiagnosticsMiddleware
{
    private readonly RequestDelegate _next;

    public RequestDiagnosticsMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task InvokeAsync(HttpContext context)
    {
        // I don't yet called Controller/Action.
        //log the essential parts of the request here

        // Call the next delegate/middleware in the pipeline
        await _next(context);
    }
}

then add your middleware as a service in your StartUp config.

public void Configure(IApplicationBuilder app)
{
    app.UseMiddleware<RequestDiagnosticsMiddleware>();

}
0
votes

Middleware has been suggested by another user.

Your other option is to use ActionFilters. These get executed immediately before the action on the controller, and allow fine grained control of the request at the controller level.

Take a look at the following link for a more detailed explanation: https://code-maze.com/action-filters-aspnetcore/