ASP. NET WEBAPI Routing basic settings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.