Asp.net mvc 4 安装Spile后,无法再访问API描述符列表

Asp.net mvc 4 安装Spile后,无法再访问API描述符列表,asp.net-mvc-4,asp.net-web-api,glimpse,Asp.net Mvc 4,Asp.net Web Api,Glimpse,我们希望在我们的ASP.net MVC项目中使用scape,但在访问Web API描述符列表时遇到问题 我们已经使用Nuget软件包管理器安装了scape.Mvc4 1.2.2 下面的代码片段获得了所有API描述符,在安装Spile之前可以正常工作。安装后,我们只得到一个空列表 IEnumerable<ApiDescription> apiDescriptors = System.Web.Http.GlobalConfiguration .Configurati

我们希望在我们的ASP.net MVC项目中使用scape,但在访问Web API描述符列表时遇到问题

我们已经使用Nuget软件包管理器安装了scape.Mvc4 1.2.2

下面的代码片段获得了所有API描述符,在安装Spile之前可以正常工作。安装后,我们只得到一个空列表

IEnumerable<ApiDescription> apiDescriptors = System.Web.Http.GlobalConfiguration
           .Configuration
           .Services
           .GetApiExplorer()
           .ApiDescriptions
IEnumerable APIRescriptors=System.Web.Http.GlobalConfiguration
配置
.服务
.GetApiExplorer()
.Api说明

有人知道为什么安装了Spile后此调用不起作用吗?

问题是Spile ASP.NET模块将所有路由封装在自己的对象中。所以API浏览器忽略了它们(认为它们不是Web API路由)

要解决此问题,必须初始化
System.Web.Http.HttpConfiguration
的新副本,而不是使用
GlobalConfiguration.Configuration

// need to create a custom configuration instance because the default one can be 
// processed by Glimpse and be thus full of wrapped routesthat the ApiExplorer 
// does not recognize.
var config = new System.Web.Http.HttpConfiguration();
WebApiConfig.Register(config);

// these line is useful if you use WebAPI Help page package
HelpPageConfig.Register(config);
Controllers.HelpController.Configuration = config;

// otherwise just get the `IApiExplorer` interface from the fresh configuration:
var apis = config.Services.GetApiExplorer().ApiDescriptions;

这听起来像是一个bug。《一瞥》没有做任何可能干扰WebAPI的具体操作,但在该调用中可能会发生一些奇怪的事情。请随时联系,这样我们就可以追踪并修复它。这也发生在我身上,我在一个干净的项目上复制了它。当我通过NuGet卸载Spile时,API又回来了。这个问题特别与ApiExplorer有关,它查看控制器和路由以为API构建元数据。有没有关于《一瞥》项目的问题(我没有看到)?几周前我确实在《一瞥》项目上打开了一个问题:我还没有得到任何回应。