[英]Customize web api help page to remove the request formats
In my web api application I am accepting Application/Json mediatype as request. 在我的Web API应用程序中,我接受Application / Json媒体类型作为请求。 So I would want to customize the help page to remove the other formats such as application/xml, text/xml, application/x-www-form-urlencoded etc. Any help is really appreciable. 因此,我想自定义帮助页面以删除其他格式,例如application / xml,text / xml,application / x-www-form-urlencoded等。任何帮助都非常可观。
As per JSON and XML Serialization in ASP.NET Web API the way to this is to call this from your Application_Start method, defined in Global.asax. 根据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);
}
Go into you help page area and find HelpPageApiModel.cshtml in DisplayTemplates 进入帮助页面区域,然后在DisplayTemplates中找到HelpPageApiModel.cshtml
and remove this lines given below or you can comment it may you need it sometime. 并删除下面给出的这行内容,或者您可以在某些时候对其进行评论。
@if (Model.SampleRequests.Count > 0)
{
<h3>Request Formats</h3>
@Html.DisplayFor(m => m.SampleRequests, "Samples")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.