Chinese display of help page description in Webapi

Source: Internet
Author: User

Transferred from: Http://edi.wang/post/2013/10/28/auto-generate-help-document-aspnet-webapi

One of the main reasons I chose the Web API was that it was possible to generate documents automatically, saving a lot of valuable time in developing the apes. Before the first generation of the Web API, the ability to automatically generate help documents is incomplete by default, and now to Web API 2, this feature has been well integrated in the form of nuget packages. Let's have a look!

First, the WEB API 2 project created with VS2013 will default to the package with the Microsoft ASP. NET Web API help page. If not, you need to manually go to NuGet to install it.

After installing this package, your Web API project directory will be more area, there is a Helppage folder, which is placed in the Helppage Generator Code, page templates and configuration files.

Without making any changes, your WEBAPI project now has the basic ability to generate documents.

Browse/help, or Areas.HelpPage.Controllers.HelpController's index () Action, to see the automatically generated API documentation:

You may notice that the "Description" field in my form is content, and your own is wooden. This is actually a need for additional configuration.

The content of this description is actually a comment of the method in the code, that is,///<summary>. If you have the experience of having a class library, you know that these things can generate XML, and many document generators use this XML as a source of metadata.

In our website, such metadata information should usually be placed in the App_Data folder instead of the default bin directory. So we're going to make some changes to the project properties of the Web API.

Open the project properties, and in the Build page, tick the XML documentation file and put it under App_Data:

Then open the HelpPageConfig.cs under Areas\helppage\app_start.

Uncomment the first code in the Register method and change the path of the XML file to the path you just set in the project Properties page.

Public Static void Register(httpconfiguration Config) { //uncomment the following to use the documentation from XML Docu mentation file.  Config. Setdocumentationprovider (new  Xmldocumentationprovider (httpcontext. Current. Server. Mappath "~/app_data/patientview.service.webapi.xml"  ... }             /span>                

Now, if you write a three-slash comment on the API method, it will be generated on the Web page.

Chinese display of help page description in Webapi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.