New WebApi project does not have default routing for API (but still works)

I created a new WebAPI MVC project, the API controllers have the path http://localhost:1234/api , and they work with this route, but the RegisterRoutes class does not contain default routing, it contains the following:

 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } 

Where is the routing API?

Greetings

Dave

+4
source share
2 answers

Visual Studio project templates create a default route that looks like this:

 routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); 

You can find this in the WebApiConfig.cs file, which is placed in the App_Start directory

http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

+4
source

He lives in another class:

 using System; using System.Collections.Generic; using System.Linq; using System.Web.Http; namespace HelloWorldApi { public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); } } } 
+1
source

All Articles