【问题标题】:Customize web api help page to remove the request formats自定义 web api 帮助页面以删除请求格式
【发布时间】:2015-01-28 06:09:23
【问题描述】:

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

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc asp.net-web-api


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      进入帮助页面区域,在 DisplayTemplates 中找到 HelpPageApiModel.cshtml

      并删除下面给出的这些行,或者您可以在需要时发表评论。

      @if (Model.SampleRequests.Count > 0)
      {
          <h3>Request Formats</h3>
          @Html.DisplayFor(m => m.SampleRequests, "Samples")
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-27
        • 2016-07-17
        • 2016-12-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多