¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Web.Http; |
| | | |
| | | namespace IStation.WebApi |
| | | { |
| | | public static class WebApiConfig |
| | | { |
| | | public static void Register(HttpConfiguration config) |
| | | { |
| | | // Web API é
ç½®åæå¡ |
| | | |
| | | // Web API è·¯ç± |
| | | config.MapHttpAttributeRoutes(); |
| | | |
| | | config.Routes.MapHttpRoute( |
| | | name: "DefaultApi", |
| | | routeTemplate: "api/{controller}/{id}", |
| | | defaults: new { id = RouteParameter.Optional } |
| | | ); |
| | | |
| | | |
| | | // Web API è·¯ç± |
| | | config.Filters.Add(new CustomHandleErrorAttribute()); |
| | | |
| | | |
| | | |
| | | //ä¿è¯æµè§å¨éé¢ä¹è½ç¨ |
| | | GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); |
| | | //é»è®¤è¿å json |
| | | GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add( |
| | | new System.Net.Http.Formatting.QueryStringMapping("datatype", "json", "application/json")); |
| | | //è¿åæ ¼å¼éæ© datatype å¯ä»¥æ¿æ¢ä¸ºä»»ä½åæ° |
| | | GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add( |
| | | new System.Net.Http.Formatting.QueryStringMapping("datatype", "xml", "application/xml")); |
| | | |
| | | } |
| | | } |
| | | } |