在config文件中修改如下代码:
//添加全局异常过滤器
config.Filters.Add(new ErrorFilterAttribute());
//设置xml格式器---用于屏蔽字典类型xml序列化错误
var xml = config.Formatters.XmlFormatter;
xml.UseXmlSerializer = true;
用于处理json 格式化实体类带有 [Serializable]混乱
var serializerSettings =
config.Formatters.JsonFormatter.SerializerSettings;
var contractResolver =
(DefaultContractResolver)serializerSettings.ContractResolver;
contractResolver.IgnoreSerializableAttribute = true;
//对日期json格式化
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
new Newtonsoft.Json.Converters.IsoDateTimeConverter()
{
DateTimeFormat = "yyyy/MM/dd HH:mm:ss"
}
);
GlobalConfiguration.Configuration.AddJsonpFormatter();
config.MessageHandlers.Add(new CustomMessageHandler());//兼容ie8原生跨域