ASP.Net Web API Help Page Returns Empty Output

I have a pre-existing MVC application in which I added the web API and self-archiving the web API using Nuget. Although the Web API controllers work fine (returning valid responses to HTTP requests), Help Manager does not find any web API methods for documenting.

In the Action Help Help Manager, Configuration.Services.GetApiExplorer () ApiDescriptions returns with 0 results.

What are the filled ApiDescriptions and are there any configuration settings that I need to set in order to set my api for documentation?

The help area is a separate area from the rest of my application. Is this the reason that the controllers cannot find the controllers? In addition, I even added that the help was processed by HelpController itself, which still did not contain API descriptions.

I also have special routing for my API controllers, so I'm not sure if this is important.

+8
asp.net-web-api documentation documentation-generation
source share
4 answers

After some searching, I found this post which also links to this post

As mentioned in the first post, Glimpse is crucial, this way to solve the problem for me is:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd"> <inspectors> <ignoredTypes> <add type="Glimpse.AspNet.Inspector.RoutesInspector, Glimpse.AspNet"/> </ignoredTypes> </inspectors> </glimpse> 

This is also a known issue, and a workaround is described in this Glimpse GitHub issue .

+6
source share

I have the same problem and I am not using Glimpse and I solve the problem as follows:

In the commentary on the ProjectName\Areas\HelpPage\Controllers\HelpController.cs constructors, since it is not called the implicit constructor of public HelpController() : this(GlobalConfiguration.Configuration) by default, is called the constructor with the parameter public HelpController(HttpConfiguration config) , and this initializing the Configuration property is an instance. And you can solve this problem as follows:

Solution 1: Comment / Delete Constructors.

 public class HelpController : Controller { private const string ErrorViewName = "Error"; // public HelpController() // : this(GlobalConfiguration.Configuration) // { // } // public HelpController(HttpConfiguration config) // { // Configuration = config; // } /// <summary> /// GlobalConfiguration By default /// </summary> protected static HttpConfiguration Configuration { get { return GlobalConfiguration.Configuration; } } public ActionResult Index() { ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider(); return View(Configuration.Services.GetApiExplorer().ApiDescriptions); } .... 

Solution 2: Insert the default constructor by adding this [InjectionConstructor] attribute.

 public class HelpController : Controller { private const string ErrorViewName = "Error"; [InjectionConstructor] public HelpController() : this(GlobalConfiguration.Configuration) { } public HelpController(HttpConfiguration config) { Configuration = config; } /// <summary> /// GlobalConfiguration By default /// </summary> protected static HttpConfiguration Configuration { get; private set; } .... 

And the problem is solved.

+2
source share

I was able to solve this by adding GlobalConfiguration.Configure (WebApiConfig.Register); into my Application_Start () method. Since my application uses OWIN, I only registered my APIs in Startup.Configuration (IAppBuilder app) .

+1
source share

After installing HelpPages from NuGet package manager - Go to WebApplication1\Areas\HelpPage\App_Start\HelpPageConfig.cs and uncomment the line below

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

Also add App_Data/XmlDocument.xml in WebApplication> Properties> Build> Check XML Documentation File

0
source share

All Articles