1, add the configuration directly in the Global.asax
Such as:
usingMvcapplication4.app_start;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.Http;usingSYSTEM.WEB.MVC;usingSystem.Web.Optimization;usingSystem.Web.Routing;namespacemvcapplication4{//Note: For instructions on enabling IIS6 or IIS7 Classic mode,//please visithttp://go.microsoft.com/?LinkId=9394801 Public classMvcApplication:System.Web.HttpApplication {protected voidApplication_Start () {RouteTable.Routes.MapHttpRoute ("WebApi","Api/{controller}/{action}/{id}", New{id =routeparameter.optional}); Arearegistration.registerallareas (); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); Bundleconfig.registerbundles (Bundletable.bundles); Bundletable.enableoptimizations=false; } }}
2. Add the WebAPIConfig.cs class in the App_start folder, and then in the Global.asax file, initialize the route map in the Application_Start method
WebAPIConfig.cs:
Global.asax
protected void Application_Start (object sender, EventArgs e) { // registering a route map at application startup Webapiconfig.register (globalconfiguration.configuration); }
ASP. NET WEBAPI Routing basic settings