首页 > 代码库 > C# WebApi 处理Area路径问题

C# WebApi 处理Area路径问题

配置WebApiConfig:

Global.asax 添加

GlobalConfiguration.Configure(WebApiConfig.Register); 

WebApiConfig配置

public static class WebApiConfig    {        public static void Register(HttpConfiguration config)        {            config.MapHttpAttributeRoutes();            //WebApi areas 中api路径            config.Routes.MapHttpRoute(               name: "DefaultApi2",               routeTemplate: "api/{area}/{controller}/{action}/{id}",               defaults: new { action = "Index", id = RouteParameter.Optional }           );            //根目录Controllers中api路径            config.Routes.MapHttpRoute(                name: "DefaultApi",                routeTemplate: "api/{controller}/{action}/{id}",                defaults: new { action = "Index", id = RouteParameter.Optional }            );        }    }

 

C# WebApi 处理Area路径问题