1

Over the past couple weeks I've been working with an ASP.NET Core Backend(Remote Ubuntu Machine, SSH only, Kestrel).

When sending an HTTP-Request to the Server oftentimes it won't be handled the way I expected it to.

Examples:

  • For POSTs: An action parameter will be null or 0 or an empty string

  • the action method isn't executed at all

Is there a way to see the headers, body, etc. of the request that arrived at the Server?

How is the body data processed before the corresponding action method is called?


I've been reading the Console Output and setting breakpoints to figure out whats going on.

Which is fine if there's an Exception thrown or theres something going wrong inside the action method.

But it doesn't help me understand what's happening before the action method is executed.

3
  • You should provide sample code and sample input to reproduce the issue. Commented Feb 25, 2020 at 16:45
  • 1
    @ManojChoudhari There is no sample code because there is no sample. I'm not asking about a very specific issue. Commented Feb 25, 2020 at 17:02
  • 1
    Set up a logging provider. learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/…. This will give you a lot of diagnostic information out of the box, and you can then add your own to it. Commented Feb 25, 2020 at 17:31

1 Answer 1

2

You can add a middleware in the pipeline to inspect any requests. In the middleware, you will have access to the HttpContext and all its properties (i.e. the request and its headers). As long as you place your app.Use() call before your app.UseMvc() call, you will have access to the request before it enters an action.

More info on middleare is here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware

Once it enters an action, you have access to the Request object in the controller as well. So you can inspect anything on the request (i.e. headers) however you prefer (locals window, watch window, etc.).

All the properties you can access if you inherit from ControllerBase are here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase

As Polyfun mentioned, the best approach would be to add robust logging.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.