ASP.NET Core HTTPRequestMessage returns strange JSON message

According to this article, ASP.NET Core MVC does not support HttpResponseMessage-returning methods by default.

If you want to keep using it, you can, by using WebApiCompatShim:

  1. Add reference to Microsoft.AspNetCore.Mvc.WebApiCompatShim to your project.
  2. Configure it in ConfigureServices(): services.AddMvc().AddWebApiConventions();
  3. Set up route for it in Configure():

    app.UseMvc(routes =>
    {
        routes.MapWebApiRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
    

Leave a Comment