惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
C
CERT Recently Published Vulnerability Notes
P
Proofpoint News Feed
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
Help Net Security
Help Net Security
月光博客
月光博客
N
News and Events Feed by Topic
Cloudbric
Cloudbric
博客园 - 司徒正美
L
LangChain Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tenable Blog
The Register - Security
The Register - Security
The Hacker News
The Hacker News
I
InfoQ
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
Schneier on Security
Schneier on Security
WordPress大学
WordPress大学
小众软件
小众软件
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
宝玉的分享
宝玉的分享
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
K
Kaspersky official blog
L
LINUX DO - 热门话题
N
News | PayPal Newsroom
F
Fortinet All Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security @ Cisco Blogs
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
Google Online Security Blog
Google Online Security Blog
S
Schneier on Security
C
Cisco Blogs
N
News and Events Feed by Topic
V2EX - 技术
V2EX - 技术
Latest news
Latest news
PCI Perspectives
PCI Perspectives
T
The Blog of Author Tim Ferriss
P
Palo Alto Networks Blog
T
Tor Project blog
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - 狂歌

关闭easyui Tabs,有意思的JS异步处理 vscode新版1.31.1使用代码检查工具ESlint支持VUE Easyui combotree 获取自定义ID属性方法 [原创]消灭eclipse中运行启动的错误:“找不到或无法加载主类”问题 [转]【Java】内部类(Inner Class)如何创建(new) spring boot项目编译出来的jar包如何更改端口号 [转] 分享一个快的飞起的maven的settings.xml文件 [转]maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test mysql字符集问题 错误代码: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_croatian_ci,IMPLICIT) for operation '=' WebApi 返值的实体值前缀加了个下划线 VS2015 异常 :遇到异常。这可能是由某个扩展导致的 【转】WebAPI使用多个xml文件生成帮助文档 C# List泛型转换,int,string 转字符,转数组 iBatisNet分布式事务的应用 MS SQL2008。 jquery.easyui.tabs 中的首个tabs被最后tabs覆盖的问题解决方法 解决easyui jQuery JS的for循环调用ajax异步问题 php网站环境无法上传的解决办法? 提高VM运行速度 [转]SQL2005系统升级手记之一-解决sa帐户被锁定
ASP.Net WebAPI中添加helppage帮助页面
狂歌 · 2016-04-13 · via 博客园 - 狂歌

一、自动创建带帮助的WebAPI

1、首先创建项目的时候选择WebAPI,如下图所示,生成的项目会自动生成帮助文档。

2、设置调用XML文档的代码

3、设置项目注释XML文档生成目录,项目——属性——生成——勾选生成XML文档——设置目录为App_Data

4、Values控制器中的代码

复制代码

 1     /// <summary>
 2     /// Values控制器
 3     /// </summary>
 4     public class ValuesController : ApiController
 5     {
 6        /// <summary>
 7        /// Get请求
 8        /// </summary>
 9        /// <returns></returns>
10         public IEnumerable<string> Get()
11         {
12             return new string[] { "value1", "value2" };
13         }
14      }

复制代码

5、查看生成效果,启动项目——点API——查看帮助文档

helpage

Help/Api/GET-api-Values

二、在已有项目中添加帮助页

1、新建一个普通的webapi项目——在nuget中添加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. 效果