自定义web api帮助页面以删除请求格式

Moh*_*med 1 .net c# asp.net asp.net-mvc asp.net-web-api

在我的web api应用程序中,我接受Application/Json mediatype作为请求.因此,我希望自定义帮助页面以删除其他格式,例如application/xml,text/xml,application/x-www-form-urlencoded等.任何帮助都非常明显.

ris*_*ism 5

根据ASP.NET Web API中JSON和XML序列化,这种方法是从Global.asax中定义的Application_Start方法调用它.

void ConfigureApi(HttpConfiguration config)
{
    // Remove the JSON formatter
    config.Formatters.Remove(config.Formatters.JsonFormatter);

    // or

    // Remove the XML formatter
    config.Formatters.Remove(config.Formatters.XmlFormatter);
}
Run Code Online (Sandbox Code Playgroud)