I have this problem, which seems pretty common, but none of the solutions I read worked in my case. I am trying to add ApiController to an existing MVC project.
When I try to access the added controller on http: // localhost: 51362 / api / test , I get this error:{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:51362/api/test'.","MessageDetail":"No type was found that matches the controller named 'test'."}
My project contains the following NuGet packages:
- Microsoft.AspNet.Mvc 5.2.3
- Microsoft.AspNet.WebApi 5.2.3
- Microsoft.AspNet.WebApi.Client 5.2.3
- Microsoft.AspNet.WebApi.Core 5.2.3
- Microsoft.AspNet.WebApi.WebHost 5.2.3
My Global.asax.cs (excerpt):
RouteTable.Routes.Clear();
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteTable.Routes.MapMvcAttributeRoutes();
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
My WebApiConfig.cs:
using System.Web.Http;
namespace End.Web
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
My new controller:
using System.Web.Http;
namespace End.Web.Controllers
{
public class TestController : ApiController
{
public string Get()
{
return "ok";
}
}
}
. , , . - ?