Global.asax.cs中的Application_Start方法添加
GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new XmlMediaTypeFormatter()); GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter());
默认就有4个Formatter。不需要添加

.net core写在public void ConfigureServices(IServiceCollection services) 方法中
builder.Services.AddControllers(op => { op.RespectBrowserAcceptHeader = true; }).AddXmlSerializerFormatters();
postman参考:


如果使用Dynamic类型,需要添加xmlInClude来指定序列化的类

本文介绍了如何在.NETCore中管理全局配置,如移除默认Formatter并添加自定义的XML和JSON格式化器。同时讨论了如何在`ConfigureServices`中处理Dynamic类型和使用`XmlInclude`进行类的序列化。
最低0.47元/天 解锁文章
2295

被折叠的 条评论
为什么被折叠?



