【问题标题】:ASP.Net Web Api 2.2 generated help files not displaying api documentationASP.Net Web Api 2.2 生成的帮助文件不显示 api 文档
【发布时间】:2016-06-08 09:51:55
【问题描述】:

我已按照步骤在此处生成 api 帮助http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages,并且一直运行良好。

今天,我注意到帮助页面在 api 组部分中没有显示任何内容。

这一行;

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

没有找到任何组进行迭代并显示 api 帮助。

@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>

我正在使用 Microsoft.AspNet.WebApi.HelpPage 版本 5.2.3,与 5.2.2 相同的问题。 Visual Studio 2015,MVC 5。

有什么想法吗?

【问题讨论】:

    标签: asp.net api asp.net-web-api


    【解决方案1】:

    好的,这是 StartUp.cs 和 Global.asax.cs 中的某些代码之间的冲突

    通常在 Global.asax 中有这一行;

    GlobalConfiguration.Configure(WebApiConfig.Register);
    

    但由于我为使用 OWIN 和配置 CORS 所做的一系列更改,我已将其注释掉。所以我的 StartUp.cs 看起来像这样;

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

    我认为我在这里调用 WebApiConfig.Register 时不需要在 Global.asax 中调用它。

    显然,要让 api 帮助工作并生成,我仍然需要在 Application_Start 方法中调用 GlobalConfiguration.Configure(WebApiConfig.Register)。

    希望对您有所帮助。

    【讨论】:

    • 为了确认,我必须从这里删除 WebApiConfig.Register 调用。
    猜你喜欢
    • 2015-06-19
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 2016-09-24
    • 1970-01-01
    • 2016-06-01
    相关资源
    最近更新 更多