配置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 } ); } }
时间: 2024-10-05 11:37:57