0

Reading about how to return status code 406 in a .NET Core API for requests that require a response in a format not supported by my API, I found that I need to set the following option in the AddMvcCore method:

services.AddMvcCore(options =>
{
    options.ReturnHttpNotAcceptable = true;
});

However, I noticed that even if a client requests for an unsupported format, the request is forwarded to the endpoint and only after processing done in Controller that the status code 406 is returned.

I would like to know if .NET Core has a ready-made solution that blocks the request, that is, returns the status code 406 without having to execute the endpoint code. I have found solutions in which Middleware can be written to perform such a task, but I would really like to know if there is an alternative built into the framework itself.

2
  • Take a look here, this may be exactly what you need: stackoverflow.com/a/55585014/1431405 Commented Sep 22, 2021 at 21:25
  • 1
    This helps me a lot in what I was looking to do, thanks @BenMatthews! Commented Sep 22, 2021 at 21:42

0

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.