如何将XML注释连接到API帮助页面?

时间:2015-04-14 00:30:35

标签: asp.net xml asp.net-web-api documentation asp.net-web-api-helppages

我正在开发一个需要API帮助页面上的文档的项目。页面已经创建,可以插入信息。但我有一些问题:

  1. 我对此非常陌生,所以我在浏览项目时遇到了一些问题。

  2. 我想引用直接位于Controller文件中的XML注释,如下所示:

    /// <summary>
    /// Get all the number of help desk tickets by their current priorities
    /// </summary>
    /// <returns></returns>
    
    
    [ActionName("GetCurrentPriority")]
    public TicketPriorities GetTicketsByCurrentPriority()
    {...
    
  3. WebApiConfig.cs文件中的HTTP路由代码如下所示:

                config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
    

    但是,我不知道如何在网页帮助页面上发表评论。我看过许多使用参数ID的例子,但似乎没有ID,我不知道如何找到参数ID或者创建它,因为“帮助”页面显示除了ID以外的所有ID。例如,我应该创建一个XMLDocument.xml文件并将所有注释放在那里吗?

1 个答案:

答案 0 :(得分:3)

你有这行代码吗?

config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

另外,不要忘记在项目属性中勾选“XML文档文件” - &gt;建立。将路径设置为App_Data\XmlDocument.xml

您可能还想禁止警告CS1591,因为会有很多类(例如在帮助生成代码中)public但不需要添加文档。

有关详细信息,请参阅此文档:http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages

相关问题