1. 安装 Microsoft.AspNet.WebApi.HelpPage 程序包
Install-Package Microsoft.AspNet.WebApi.HelpPage
2. 注册 Area
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
}
3. HelpPageConfig 启用 SetDocumentationProvider
WebApplication/Areas/HelpPage/App_Start/HelpPageConfig.cs 目录下,找到下面代码,并取消注释(App_Data 改为 bin):
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/XmlDocument.xml")));
}
4. WebApplication Build 配置 XmlDocument 输出路径
5. ValuesController 代码
/// <summary>
/// Values控制器
/// </summary>
public class ValuesController : ApiController
{
........
/// <summary>
/// POST 操作
/// </summary>
/// <param name="value">value值</param>
public void Post([FromBody]string value)
{
}
}
6. 效果
Help Page
Help/Api/POST-api-Values