I have a simple WebAPI project and for convenience I created another controller (with the same inheritance and behavior, like the other API controllers, let’s call it App for now) for login, registration and to load the single page site.
The base location of App is ‘/’ and the api endpoints are under ‘/api/’.
If I call methods from under ‘/api/’ the response is a json object as expected. But when I call register (/register) from App, for example, it succeeds, it returns the newly created user entity wrapped in an ‘Ok’ call, but some middleware blocks the process and gives back the status code 406 with an empty http body.
I only use the default server setup, I did not tamper with middlewares. I added swagger with the most basic tutorial, enabled static resources but that is all.
I know what 406 is, I set the Accept header to ‘application/json’ in my client. When I debugged the call in visual studio, it did contained the Accept information in the Request property.
This only happens if I’m not in the ‘/api/’ route. How can I change this behavior so that whatever I put in ‘Accept’, asp.net tries to serialize the data in that format? Because now it somehow decides to ignore the header’s intention if the current route is not under ‘/api/’
Edit: I found a very weak solution. If I manually set the status code (for cases other than 200), than manually call the Json method, to return a JsonResult, it works. But this is not what you expect from a framework, that should find the appropriate converter for the given Accept value.