Skip to main content
 首页 » 编程设计

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

2024年02月01日27shihaiming

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

请您参考如下方法:

根据 JSON and XML Serialization in ASP.NET Web API方法是从 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); 
}