1.直接在Global文件中配置:
class="code_img_closed" alt="" src="/Upload/Images/2017012105/0015B68B3C38AA5B.gif">1 var formatters = GlobalConfiguration.Configuration.Formatters; 2 var jsonFormatter = formatters.JsonFormatter; 3 var settings = jsonFormatter.SerializerSettings; 4 settings.Formatting = Newtonsoft.Json.Formatting.Indented; 5 settings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; 6 settings.ContractResolver = new CamelCasePropertyNamesContractResolver();logs_code_collapse">View Code
2.配置任意的返回格式json和xml
1config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "json", "application/json")); 2config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "xml", "application/xml"));View Code
3.使用Cors跨域框架配置跨域
3.1在webapi控制器下的配置