How to add HelpPage to your ASP. NET page

Source: Internet
Author: User

How to add HelpPage to your ASP. NET page

Recently I wrote some webapis, so I need to develop a set of API help documentation. google found that this can be automatically generated. The following describes how to automatically generate HelpPage.

Reference: http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages

In fact, I also followed the above statement step by step, but the above is English. I have a simple translation, and I have made changes in some of them. I also want to record it here!

1. Create a project:

   

Confirm the new project, right-click the project properties, and make sure that the current project is Framework4.5 (4.0 and below the installation package is not successfully installed, remember, this is a blood Lesson)

  

2. Add a reference package

Right-click to reference and choose to manage the NuGet package. (You must configure this first. You can configure Baidu for details)

  

Search for helppage. The first helppage package is the asp.net helppage package that we need to add.

  

Click "Install". The installation speed depends on your network speed. It is very slow on my side. Sometimes you have to install it many times.

  

Now the Help page has been generated. Right-click the project and choose debug> to start a new instance. Then, enter/Help at the end of the page URL. (Note: our ports should not be the same. No problem)

  

At this time, you will find that there is nothing on the page, don't worry, go down.

3. Modify the location where the configuration file is generated

The first thing to note is that this package will generate all documents based on the XML configuration file generated by the project, so you must first generate this XML file for your project.

Right-click the project and select properties, and then generate a column to select the output file to the XML document file. The path and name will follow your instructions, as long as they correspond to the following configuration, I use the default one directly.

  

After that, we need to write the xml Path to the program. After the configuration is complete, open Areas/HelpPage/App_Start/HelpPageConfig. on the cs page, remove the comments in the Register function, and modify them to the correct path.

Config. setDocumentationProvider (XmlDocumentationProvider (HttpContext. current. server. mapPath (config. setSampleObjects (Dictionary <Type,> // This section needs to be released mainly for sample {(), {(IEnumerable <>), [] {,});

    

4. Add a Controller

OK. Now the basic conditions are ready, and only the items to be displayed are left. Create a controller and then add an interface.

IEnumerable <> [] {, Get (}

 

    

OK. Now the page has changed. You can compile the Help page as needed.

5. APIs of other styles

It can be found that some restapis are generated by default, and I don't catch a cold at this point, so I plan to write it in another way:

                                                                          [System.Web.Http.AcceptVerbs(         [System.Web.Http.ActionName(           TestMethod( msg1,               msg1 +      }

 

At this time, we need to modify the configuration file. Otherwise, you will find that its API name is changed to the controller name.

  

Find the path App_Start/WebApiConfig. cs and modify the Register function as follows:

                           name:                  routeTemplate:                  defaults:  { id =          }

 

Refresh the page:

  

OK. This is what I want.

For personalization, I need to modify the title and the content of the introduction section, find the file: Area/Views/Help/Index. cshtml, and modify some Code as follows:

ILookup @ ViewBag. Title Introduction

Current page:

  

7. pitfalls

When I was using it, I found a hole in it and found the file Areas/HelpPage/ModelDescriptions/ModelNameHelper. cs.

There is a piece of code in it: genericTypeName = genericTypeName. Substring (0, genericTypeName. IndexOf ('''));

This code, if there is no ''' in the genericTypeName string, will cause a problem, so I modified the Code:

                            genericTypeName = genericTypeName.Substring(0, index != -1 ? index : genericTypeName.Length);

In fact, many functions do not need to be published, so we can set them using the following code:

 [ApiExplorerSettings(IgnoreApi=  HttpResponseMessage Get( id) {  }

 

Okay, this is basically the problem. Now HelpPage is ready for use. In the next article, I plan to write Test Client, that is, put a Test tool in the help page, in this way, it is very convenient during development.

Remember this and learn later!

 

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.