Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);

        }
    }
like image 551
DalSoft Avatar asked Sep 20 '13 16:09

DalSoft


1 Answers

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.

like image 113
Hongye Sun Avatar answered Sep 29 '22 23:09

Hongye Sun