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 }
            );


        }
    }

 

posted @ 2017-03-25 14:55  鞍山老菜鸟  阅读(2540)  评论(0编辑  收藏  举报