Short Walks: 406 Error While Creating a .NET Core API
If you've come across this situation with .NET Core, then we have a solution for you. Read on to learn more!
Join the DZone community and get the full member experience.
Join For FreeI'm afraid this is another of those: "What has AddMvc() ever done for us" posts. Today, I was creating a brand new .NET Core 2.1 API and, instead of calling AddMvc in ConfigureServices, I instead used AddMvcCore:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore();
When I tried to access the API, I got a 406 error. The fix is very simple (and one that using AddMvc()
does for you:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddJsonFormatters();
Published at DZone with permission of Paul Michaels, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments