ASP. NET Web API generates help documents based on code comments

Source: Internet
Author: User

Use Visual Studio to create a new ASP. NET Web API project, run directly, view the help documentation to see the following API helper instructions

How to display the description in description.

1. Open Controllers=>valuescontroller, add comments for each API (Summary)

 Public classvaluescontroller:apicontroller{/// <summary>    ///GET api/values/// </summary>    /// <returns></returns>     Publicienumerable<string>Get () {return New string[] {"value1","value2" }; }    /// <summary>    ///GET API/VALUES/5/// </summary>    /// <param name= "id" ></param>    /// <returns></returns>     Public stringGet (intID) {return "value"; }    /// <summary>    ///POST api/values/// </summary>    /// <param name= "value" ></param>     Public voidPost ([Frombody]stringvalue) {    }    /// <summary>    ///API/VALUES/5/// </summary>    /// <param name= "id" ></param>    /// <param name= "value" ></param>     Public voidPut (intID, [frombody]stringvalue) {    }    /// <summary>    ///API/VALUES/5/// </summary>    /// <param name= "id" ></param>     Public voidDelete (intID) {}}

2. Open the Project's property page =>build, check output=>xml documentation file: and enter the path to the document that holds the project notes.

3. Modify the following code

Areas=>helppage=>app_start=>helppageconfig.cs, cancel the line comment

Config. Setdocumentationprovider (New Xmldocumentationprovider (HttpContext.Current.Server.MapPath ("~/app_data/ Xmldocument.xml ")));

Note that the path must be the same as the path you configured above.

4. Rebuild the project and generate the Xmldocument.xml file under App_Data

5. Check the help page again to see that the API comments have increased.

ASP. NET Web API generates help documents based on code comments

Related Article

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.