asp.net-mvc WebApi 帮助页面说明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24284413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:44:28  来源:igfitidea点击:

WebApi Help Page Description

asp.net-mvcasp.net-web-api

提问by heymega

What populates the Webapimethod's description on the helper page and the introduction paragraph?

Webapi帮助页面和介绍段落上的方法描述是什么?

enter image description here

在此处输入图片说明

回答by nznoor

According to this articleyou can use XML documentation comments to create the documentation. To enable this feature, open the file Areas/HelpPage/App_Start/HelpPageConfig.cs and uncomment the following line:

根据本文,您可以使用 XML 文档注释来创建文档。要启用此功能,请打开文件 Areas/HelpPage/App_Start/HelpPageConfig.cs 并取消注释以下行:

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

Now enable XML documentation. In Solution Explorer, right-click the project and select Properties. Select the Build page.

现在启用 XML 文档。在解决方案资源管理器中,右键单击项目并选择属性。选择构建页面。

Under Output, check XML documentation file. In the edit box, type “App_Data/XmlDocument.xml”.

在输出下,检查 XML 文档文件。在编辑框中,键入“App_Data/XmlDocument.xml”。

Add some documentation comments to the controller methods. For example:

向控制器方法添加一些文档注释。例如:

/// <summary>
/// Gets some very important data from the server.
/// </summary>
public IEnumerable<string> Get()
{
    return new string[] { "value1", "value2" };
}

/// <summary>
/// Looks up some data by ID.
/// </summary>
/// <param name="id">The ID of the data.</param>
public string Get(int id)
{
    return "value";
}

回答by CodeNotFound

To view the description you need to follow this :

要查看描述,您需要遵循以下步骤:

  1. Every action in your Customercontroller must have a XML documentation
  2. Open the properties of the project that contains your controllers and enable XML documenation like this : enter image description here
  3. In the Registermethod for HelpPageConfigclass ( Areas/HelpPage/App_Start/HelpPageConfig.cs) uncomment the line 19 and don't forget to change the file path like this :

    config.SetDocumentationProvider(new XmlDocumentationProvider(
        HttpContext.Current.Server.MapPath("~/App_Data/MvcApplication4.XML"))
    );
    
  1. 客户控制器中的每个操作都必须有一个XML 文档
  2. 打开包含您的控制器的项目的属性并启用 XML 文档,如下所示: 在此处输入图片说明
  3. HelpPageConfig类的注册方法(Areas/HelpPage/App_Start/HelpPageConfig.cs) 中取消注释第 19 行,不要忘记像这样更改文件路径:

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

This all you must do. Last thing is to include the file created in App_Data in your project so the file will be deployed in production.

这一切都是你必须做的。最后一件事是将在 App_Data 中创建的文件包含在您的项目中,以便该文件将部署到生产中。

回答by ChrisC

For those of you using VB.NET, you seem to have to do it a little differently.

对于那些使用 VB.NET 的人来说,您似乎必须做一些不同的事情。

You have to go to the "Compile" tab (there is no Build tab) for the Web API project, then ensure "Generate XML documentation file" checkbox is checked.

您必须转到Web API 项目的“编译”选项卡(没有构建选项卡),然后确保选中“生成 XML 文档文件”复选框。

enter image description here

在此处输入图片说明

The output actually gets put in /bin/{projectName}.xml, so now you have to change the SetDocumentationProvidercall to point to the path "~/bin/{projectname}.xml" (obviously, replace {projectname} with your actual project name).

输出实际上放在/bin/{projectName}.xml 中,所以现在您必须更改SetDocumentationProvider调用以指向路径“ ~/bin/{projectname}.xml”(显然,将 {projectname} 替换为您的实际项目姓名)。

This seems smelly, so please let me know if anybody finds a different way to do it.

这看起来很臭,所以如果有人找到不同的方法,请告诉我。