简体   繁体   中英

Customize web api help page to remove the request formats

In my web api application I am accepting Application/Json mediatype as request. 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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM