I am using web api with ASP.NET MVC 4.
I have the following named controller
- CustomerController : Controller
- CustomerApiController : ApiController
Earlier my CustomerApiController was named CustomersController so to access it, I simply had to punch in the following url
localhost/api/Customers
but now I have to keep the api controller name as CustomerApiController. I want to be able to hit the same method using localhost/api/Customers what changes do I have to make ?
I have tried making some changes in the RouteConfig.cs file. I tried adding the following to the RegisterRoutes method, but none of them worked.
routes.MapHttpRoute(
name: "API Default",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Customers",
url: "api/customer/",
defaults: new { controller = "CustomerApi", action = "Get", id = UrlParameter.Optional }
);
Please can some one guide me on this. Thanks