Web API Help Pages always empty
Asked Answered
S

1

5

I've added Help pages Nuget package to create documentation for my Web API but it doesn't work for me, no API methods are shown.

I uncommented line :

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

I checked box XML documentation file and set path to App_Data/XmlDocument.xml

I don't use Glimpse as many solutions here write about it.

I even installed nuget package for help pages with authorization but it doesn't help

What is wrong with this? If I start empty project than it is working fine, but this API is too big to start all over again.

Silo answered 2/7, 2015 at 10:35 Comment(2)
did you find a solution? Having same problem.Plourde
No, unfortunately.Silo
C
9

In case you are using OWIN as middleware (just like me), you may be initializing a new HttpConfiguration inside it´s startup method. The problem is that the HelpController and the HelpPageConfig are using GlobalConfiguration.Configuration, which seems to be wrong. What helped me:

Step 1: make the startup HttpConfiguration a static field

[assembly: OwinStartup(typeof(MyProject.API.Startup))]
namespace MyProject.API
{
    public class Startup
    {
        //new
        public static HttpConfiguration HttpCfg;
        //

        public void Configuration(IAppBuilder app)
        {
            HttpCfg = new HttpConfiguration();
            WebApiConfig.Register(HttpCfg);
            app.UseWebApi(HttpCfg);

            AreaRegistration.RegisterAllAreas();
        }
    }
}

Step 2: go to HelpPageAreaRegistration and edit the RegisterArea method like this

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "HelpPage_Default",
        "Help/{action}/{apiId}",
        new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });

    //old
    //HelpPageConfig.Register(GlobalConfiguration.Configuration);

    //new
    HelpPageConfig.Register(Startup.HttpCfg);
}

Step 3: go to HelpController and edit the standard constructor like this

//old
//public HelpController() : this(GlobalConfiguration.Configuration){ }

//new
public HelpController() : this(Startup.HttpCfg){ }

I hope this helps and isn't too late ;)

Catmint answered 17/11, 2016 at 21:41 Comment(1)
@Catmint Did you keep the default AreaRegistration.RegisterAllAreas() in Global.ascx.cs?Maleki

© 2022 - 2024 — McMap. All rights reserved.