简体   繁体   English

WebApi帮助页面无法从XML文件读取

[英]WebApi Help Page not reading from XML file

I have added the .net webapi help pages nuget project to our webapi to generate the help docs. 我已经将.net webapi帮助页面nuget项目添加到了我们的webapi中,以生成帮助文档。

I added as follows on the command line; 我在命令行上添加了以下内容;

Install-Package Microsoft.AspNet.WebApi.HelpPage 安装包Microsoft.AspNet.WebApi.HelpPage

Its the current version installed. 其当前版本已安装。 I then set the output of the webapi project to output to 然后,我将webapi项目的输出设置为输出到

App_Data/XmlDocument.xml App_Data / XmlDocument.xml

This is following the example here; 这是这里的示例;

WebApi Help Tutorial WebApi帮助教程

and this is being generated fine. 而且这种情况还不错。

I then un-commented the line; 然后我取消了评论。

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

again as per the link. 再次根据链接。

However, when I run my api and navigate to the webapi/help url. 但是,当我运行api并导航到webapi / help网址时。 The model being returned is null? 返回的模型为空? (no errors appear to be being thrown either). (也没有抛出任何错误)。

I then have the header of the layout being displayed, but no api documentation? 然后,我将显示布局的标题,但是没有api文档?

One thing to add is I am using OAuth in this api. 要添加的一件事是我正在此api中使用OAuth。 (Although its resolving the route so can this be causing any issues?) For reference this is my startup.cs (尽管它解决了路由问题,但这会引起任何问题吗?)作为参考,这是我的startup.cs

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

        LoggingConfig.RegisterLogger();

        config.DependencyResolver = new UnityDependencyResolver(
            UnityConfig.GetConfiguredContainer());


        ConfigureOAuth(app);

        WebApiConfig.Register(config);
        app.UseCors(CorsOptions.AllowAll);
        app.UseWebApi(config);

        AreaRegistration.RegisterAllAreas();

    }

Ok, 好,

I managed to sort it, and it was due to the fact Startup.cs is being used instead. 我设法对其进行排序,这是由于使用了Startup.cs代替。

Hence I need to change it to use Startup.HttpConfiguration as opposed to GlobalConfiguration.Configuration 因此,我需要将其更改为使用Startup.HttpConfiguration而不是GlobalConfiguration.Configuration

Heres my updated Startup.cs 这是我更新的Startup.cs

public static HttpConfiguration HttpConfiguration { get; private set; }
    public static OAuthBearerAuthenticationOptions OAuthBearerOptions { get; private set; }

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

        LoggingConfig.RegisterLogger();

        HttpConfiguration.DependencyResolver = new UnityDependencyResolver(
            UnityConfig.GetConfiguredContainer());


        ConfigureOAuth(app);

        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(HttpConfiguration);
        app.UseCors(CorsOptions.AllowAll);
        app.UseWebApi(HttpConfiguration);
    }

I then had to modify the following help files; 然后,我不得不修改以下帮助文件;

HelpPageAreaRegistration.RegisterArea HelpPageAreaRegistration.RegisterArea

specifically, to be; 具体而言

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

        HelpPageConfig.Register(Startup.HttpConfiguration);
    }

and the

HelpController.cs HelpController.cs

    public HelpController()
        : this(Startup.HttpConfiguration)
    {
    }

Hopefully this helps someone. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM