Disable JSON Support in ASP.NET MVC Web API

后端 未结 2 1652
天命终不由人
天命终不由人 2021-01-26 15:39

In the creation of our new MVC Web API-based service, we want to focus on XML to begin with and add JSON functionality later as an enhancement, using the full release with nativ

2条回答
  •  无人共我
    2021-01-26 16:06

    All you have to do is to remove JSON media formatters.

    // Identify JSON formatters in global config.
    var jsonMediaTypeFormatters = GlobalConfiguration.Configuration.Formatters
        .Where(x => x.SupportedMediaTypes
        .Any(y => y.MediaType.Equals("application/json", StringComparison.InvariantCultureIgnoreCase)))
        .ToList();
    
    // Remove formatters from global config.
    foreach (var formatter in jsonMediaTypeFormatters)
    {
        GlobalConfiguration.Configuration.Formatters.Remove(formatter);
    }
    

提交回复
热议问题