using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; /// /// WebApiConfig 的摘要描述 /// public class WebApiConfig { public static string UrlPrefixRelative { get { return "~/api"; } } public static void Register(HttpConfiguration config) { // TODO: Add any additional configuration code. // Web API routes config.MapHttpAttributeRoutes(); //config.Routes.MapHttpRoute( // name: "AppFollowerApi", // routeTemplate: "api/appfollower/{id}", // defaults: new { controller = "appFollower", id = RouteParameter.Optional } //); //config.Routes.MapHttpRoute( // name: "AppApi", // routeTemplate: "appapi/{controller}/{id}", // defaults: new { id = RouteParameter.Optional } //); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Configure route for controllers under app_code/appapi //config.Routes.MapHttpRoute( // name: "AppApi", // routeTemplate: "appapi/{controller}/{id}", // defaults: new { controller = "app{controller}", id = RouteParameter.Optional } //); // WebAPI when dealing with JSON & JavaScript! // Setup json serialization to serialize classes to camel (std. Json format) //var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter; var formatter = config.Formatters.JsonFormatter; formatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); } }