Introduction

In this article we will define the process of creating the help page in the ASP .NET Web API. For creating the help page first we need to install the ASP .NET and Web Tools 2012.2 update. When we install this update it integrates the help page into the web API.

Step 1

We can install this update from this link: Click me

Step 2

We create the Web API application using the following:

  • Start the Visual Studio 2012.
  • Click on New Project and select the MVC4 application.
  • Now select the Web API application from the template.

Step 3

Now we see the Areas folder in Solution Explorer. The Areas folder contains the help page folder.

Step 4

Now we execute the application.

When we execute the application we will see the API help page Link.

When we click on API help Link then open a API summary page.

Step 5

There are more links that are connected to the detailed information page. We will see this image for the Response body format.

Step 6

Adding the API Documentation

For adding the API Documentation go to Areas/HelpPage/App_Start/HelpPageConfig.cs and uncomment the following code in this file.

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

Step 7

Now we enable the XML Documentation. In the Solution Explorer right-click on the project and select the properties.

Then open this page.

In this window we select the Output and check the XML documentation file and in the edit box we type the following line in App_Data/XMLDocument.xml.

Step 8

Now we open the Valuescontroller API controller and add the some documentation comment For example:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Net.Http;

using System.Web.Http;

namespace MvcApplication4.Controllers

{

publicclassValuesController : ApiController

{

///<summary>

///Fetch some important data from the server.

///</summary>

publicIEnumerable<string> Get()

{

returnnewstring[] { "value1", "value2" };

}

///<summary>

/// Take Data by ID.

///</summary>

///<param name="id">The ID of the data.</param>

publicstring Get(int id)

{

return"value";

}

Step 9

Now we again run the application and we see that the documentation string is shown in the API table.

We can modify the layout of the API application such as Title, font size, color etcetera. Here we see an example of modifying the formatting of the API.

Here is an Index.cshtml file. For modifying the layout we perform the change in this file. This file exists in the Solution Explorer Areas/HelpPage/Views/Help/Index.cshtml.

@using System.Web.Http

@using System.Web.Http.Description

@using System.Collections.ObjectModel

@using MvcApplication4.Areas.HelpPage.Models

@model Collection<ApiDescription>

@{

ViewBag.Title = "This is ASP.NET Web API Help Page";

// Group APIs by controller

ILookup<string, ApiDescription> apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor.ControllerName);

}

<header>

<divclass="content-wrapper">

<divclass="float-left">

<h1>@ViewBag.Title</h1>

</div>

</div>

</header>

<divid="body">

<sectionclass="featured">

<divclass="content-wrapper">

<h2>  <fontcolor="Blue">Introduction</font></h2>

<p>

<fontcolor="Red"size="20pt">

Provide a general description of your APIs here.

</font>

</p>

</div>

</section>

<sectionclass="content-wrapper main-content clear-fix">

@foreach (var group in apiGroups)

{

@Html.DisplayFor(m => group, "ApiGroup")

}

</section>

</div>

@section Scripts {

<linktype="text/css"href="~/Areas/HelpPage/HelpPage.css"rel="stylesheet"/>

}

Now it can look like this:

Creating the Help Page in ASP.NET Web API的更多相关文章

  1. Asp.Net Web API 2第十七课——Creating an OData Endpoint in ASP.NET Web API 2(OData终结点)

    前言 很久没更新博客了,加上刚过年,现在准备重新开战,继续自己的学习之路.本文已同步到Web API2系列文章中http://www.cnblogs.com/aehyok/p/3446289.html ...

  2. [转]Asp.Net Web API 2第十七课——Creating an OData Endpoint in ASP.NET Web API 2(OData终结点)

    本文转自:http://www.cnblogs.com/aehyok/p/3545824.html 前言 很久没更新博客了,加上刚过年,现在准备重新开战,继续自己的学习之路.本文已同步到Web API ...

  3. Creating Help Pages for ASP.NET Web API -摘自网络

    When you create a web API, it is often useful to create a help page, so that other developers will k ...

  4. ASP.NET Web API系列教程目录

    ASP.NET Web API系列教程目录 Introduction:What's This New Web API?引子:新的Web API是什么? Chapter 1: Getting Start ...

  5. 【ASP.NET Web API教程】2 创建各种Web API

    原文 [ASP.NET Web API教程]2 创建各种Web API Chapter 2: Creating Web APIs第2章 创建各种Web API 本文引自:http://www.asp. ...

  6. ASP.NET Web API系列教程(目录)(转)

    注:微软随ASP.NET MVC 4一起还发布了一个框架,叫做ASP.NET Web API.这是一个用来在.NET平台上建立HTTP服务的Web API框架,是微软的又一项令人振奋的技术.目前,国内 ...

  7. [转]ASP.NET Web API系列教程(目录)

    本文转自:http://www.cnblogs.com/r01cn/archive/2012/11/11/2765432.html 注:微软随ASP.NET MVC 4一起还发布了一个框架,叫做ASP ...

  8. 使用ASP.NET web API创建REST服务(二)

    Creating a REST service using ASP.NET Web API A service that is created based upon the architecture ...

  9. 使用ASP.NET web API创建REST服务(三)

    本文档来源于:http://www.cnblogs.com/madyina/p/3390773.html Creating a REST service using ASP.NET Web API A ...

随机推荐

  1. OpenSSL 中 RSA 加密解密实现源代码分析

    1.RSA 公钥和私钥的组成.以及加密和解密的公式: 2.模指数运算: 先做指数运算,再做模运算.如 5^3 mod 7 = 125 mod 7 = 6 3.RSA加密算法流程: 选择一对不同的.而且 ...

  2. WIN32 SDK对COM的支持

     

  3. (https专业版)2018年1月5日高仿互站仿友价T5虚拟交易+实物交易商城-站长交易源码送手机版程序10套模版+首页微信登陆+头部下拉导航

    (https专业版)2018年1月5日高仿互站仿友价T5虚拟交易+实物交易商城-站长交易源码送手机版程序10套模版+首页微信登陆+头部下拉导航 首页支持微信登陆,只有第8套模板支持(endv模板),后 ...

  4. 8. 利用反射机制, ListArray,intent来实现多Activity的切换

    package com.example.thenewboston; import android.app.ListActivity; import android.content.Intent; im ...

  5. 一个用于发送HTML格式邮件的类

    以下类是在网上孙钰佳的版本上改写而来,主要变化了三点:1.去掉了附件部分:2.形式从纯Java类改成可注入方式:3.to,cc和bcc都变成了一堆人,以前是一个人. 以下是Java类的代码: impo ...

  6. 《Java程序设计》第16周周四:GUI编程及文件对话框的使用

    第一部分:实验项目  项目一:文件及选择 目的:了解文件对话框的用法,熟悉GUI中事件驱动的核心步骤. 1. 阅读博文 "JFileChooser (Java Swing提供的文件选择对话框 ...

  7. ZH奶酪:AngularJS判断checkbox/复选框是否选中并实时显示

    最近做了一个选择标签的功能,把一些标签展示给用户,用户选择自己喜欢的标签,就类似我们在购物网站看到的那种过滤标签似的: 简单的效果如图所示: 首先看一下html代码: <!DOCTYPE htm ...

  8. UITabBarController 的配置

    UITabBarController --> UITabBar Customizing Appearance backgroundImage  背景图片 selectedImageTintCol ...

  9. locate 命令(转)

    原文:http://www.cnblogs.com/peida/archive/2012/11/12/2765750.html locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法 ...

  10. TP3.2 APP_DEBUG=false关闭调试后访问不了。页面错误!请稍后再试~

    在APP_DEBUG=true时是没问题的,在APP_DEBUG=false时才会出现找不到模板的问题.  经过排查可能是模板文件找不到问题,之前是这么写的. 改为这个就好了. ----------- ...