禁用ASP.NET MVC的Web API支持JSON [英] Disable JSON Support in ASP.NET MVC Web API

查看:105
本文介绍了禁用ASP.NET MVC的Web API支持JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创造我们的新的基于API的MVC的Web服务,我们希望专注于XML来开始和以后添加JSON功能的增强,使用充分释放与本地JSON.NET支持。为此,我们要prevent服务接受请求或提供的JSON响应,以避免建立我们期待打破任何功能。

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 native JSON.NET support. To that end, we want to prevent the service accepting requests or giving responses in JSON to avoid establishing any functionality we are expecting to break.

有没有一种方法来禁用ASP.NET MVC API中JSON支持?

Is there a way to disable JSON support in the ASP.NET MVC API?

推荐答案

所有你需要做的是去除JSON媒体格式化。

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);
}

这篇关于禁用ASP.NET MVC的Web API支持JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆