WebApi关于配置全局返回Json数据格式时间以及命名小写

1.直接在Global文件中配置:

  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();
View Code
image

image

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

image

3.使用Cors跨域框架配置跨域

image

3.1在webapi控制器下的配置

image

转载于:https://www.cnblogs.com/M-LittleBird/p/6323147.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值