0

I have followed the steps to generate api help here http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages and this has been working fine.

Today, I've noticed that the Help page is not displaying anything in the api groups section.

This line;

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

is not finding any groups to iterate through and display the api help for.

@using System.Web.Http
@using System.Web.Http.Controllers
@using System.Web.Http.Description
@using System.Collections.ObjectModel
@using MyCompany.WebApi.Areas.HelpPage.Models
@model Collection<ApiDescription>

@{
    ViewBag.Title = "Web API Help Page";

    // Group APIs by controller
    ILookup<HttpControllerDescriptor, ApiDescription> apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor);
}

<link type="text/css" href="~/Areas/HelpPage/HelpPage.css" rel="stylesheet" />
<header class="help-page">
    <div class="content-wrapper">
        <div class="float-left">
            <h1>@ViewBag.Title</h1>
        </div>
    </div>
</header>
<div id="body" class="help-page">
    <section class="featured">
        <div class="content-wrapper">
            <h2>Introduction</h2>
            <p>
                Provide a general description of your APIs here.
            </p>
        </div>
    </section>
    <section class="content-wrapper main-content clear-fix">
        @foreach (var group in apiGroups)
        {
            @Html.DisplayFor(m => group, "ApiGroup")
        }
    </section>
</div>

I'm using Microsoft.AspNet.WebApi.HelpPage version 5.2.3, and same issue with 5.2.2. Visual Studio 2015, MVC 5.

Any ideas?

1 Answer 1

0

Ok it was a conflict between some code in StartUp.cs and Global.asax.cs

Normally in Global.asax you have this line;

GlobalConfiguration.Configure(WebApiConfig.Register);

but I had commented this out because of a bunch of changes I had done to use OWIN and get CORS configured. So my StartUp.cs looked like this;

public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            //Load any config settings from web.config
            MyConfiguration.Load();

            //Create AutoMapper maps.
            AutoMapperConfigurator.Configure();

            //write web api into Owin server pipeline.
            HttpConfiguration config = new HttpConfiguration();
            WebApiConfig.Register(config);
            //Get CORS working.
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            app.UseWebApi(config);
        }

and I thought as I'm calling WebApiConfig.Register in here I didn't need to call it in Global.asax.

Clearly, to get the api help working and generated I do still need to call GlobalConfiguration.Configure(WebApiConfig.Register) in the Application_Start method.

Hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

To confirm, I had to remove the WebApiConfig.Register call from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.