Reputation: 75
I have an Asp.Net Web Forms app that I am trying to add a webapi controller to. When I call the URI for the controller, I get the 'No type was found that matches the controller named' error. I have read through all the threads here and on other sites but no resolution as yet.
My controller class has the following:
`public class RelationalController : ApiController{
[System.Web.Http.ActionName("InitializeClient")]
[System.Web.Http.HttpPost]
public Dictionary<string, object>
InitializeClient(Dictionary<string, object> jsonResult)
{
this.BindData();
return pivotClient.GetJsonData(jsonResult["action"].ToString(),
ProductSales.GetSalesData(), jsonResult["clientParams"].ToString());
}
}`
I have the following setup in Global.asax.cs:
`
protected void Application_Start(Object sender, EventArgs e)
{
RegisterRoutes();
}
protected static void RegisterRoutes()
{
RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}");
RouteTable.Routes.MapHttpRoute(
name: "Relational",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { controller = "Relational", id =
System.Web.Http.RouteParameter.Optional }
);
}`
When I test the call in Postman I get the following:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:57802/api/Relational/InitializeClient/'.","MessageDetail":"No type was found that matches the controller named 'Relational'."}
I've verified I only have one controller named RelationalController. It's the only controller defined in the app. It's in a folder call api at the root of my app.
Does anyone know what might be the issue, or can you suggest some ways to troubleshoot further?
Upvotes: 1
Views: 113
Reputation: 43959
you can try attribute routing. Add MapMvcAttributeRoutes()
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: “Default”,
url: “api/{controller}/{action}/{id}”,
defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }
);
}
and change the action
[HttpPost("~/api/Relational/InitializeClient")]
public Dictionary<string, object> InitializeClient(Dictionary<string, object> jsonResult)
Upvotes: 1