Can't get ASP.NET Web API 2 Help pages working when using Owin

DalSoft picture DalSoft · Sep 20, 2013 · Viewed 11.9k times · Source

I've installed the correct package for Web Api 2

Install-Package Microsoft.AspNet.WebApi.HelpPage -Pre 

But the help area is not being mapped and is returning 404 (Web Api working fine). I'm using Microsoft.Owin.Host.SystemWeb as the host. Below is my Startup code.

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            //Required for MVC areas new HttpConfiguration() doesn't work with MVC
            var config = GlobalConfiguration.Configuration;

            AreaRegistration.RegisterAllAreas();

            WepApiStartup.Configure(config);

            app.UseWebApi(config);

        }
    }

Answer

Hongye Sun picture Hongye Sun · Sep 20, 2013

GlobalConfiguration.Configuration is web host specific HttpConfiguraiton, which should only be used with web host scenario. Use it with OWIN host will cause unexpected issues.

Please use the following code instead:

public class Startup
{
    public static HttpConfiguration HttpConfiguration { get; private set; }

    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration = new HttpConfiguration();

        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(HttpConfiguration);

        app.UseWebApi(HttpConfiguration);
    }
}

Replace all GlobalConfiguration.Configuration with Startup.HttpConfiguration in the project include help page files.