WebAPI 踩坑


使用 WebAPI ,Controller 返回 object 类型,在Google浏览器中会报错:“ObjectContent`1”类型未能序列化内容类型“application/xml; charset=utf-8”的响应正文 

原因:Google和火狐显示的是XML,只有IE内核显示才是Json。

解决:把XmlFormatter序列化方式去掉,在webapiConfig里面加一行代码,GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

C