I am trying to add one more controller to our existing Web API. The controllers are like
public class TDataController : ApiController
{
[HttpGet]
public HttpResponseMessage Getdetails(string ROOM, DateTime DOB_GT, DateTime DOB_LT, string STATUS_TYPE)
{
// Code for the controller
}
}
and this is the controller I am trying to add in the same Application
public class TDataSubDateController : ApiController
{
[HttpGet]
public HttpResponseMessage Getdetails(string ROOM, string STATUS_TYPE, DateTime? SUBDATE_GT = null, DateTime? SUBDATE_LT = null)
{
//Code for the controller
}
}
When I am trying to call the second controller like
http://localhost:33823/api/TDataSubDate?ROOM=xxx&STATUS_TYPE=xxx&SUBDATE_GT=xxxx&SUBDATE_LT=xxxx
But it throws the HTTP 404 Page Not Founderror. Do I have to create a different route in the WebConfig.cs. The RouteConfig.cs currently looks like
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
WebApiConfig.csif you used default template. Routing is all explained here.