Swagger不支持次要版本ASP.NET Webapi

时间:2018-02-19 13:25:42

标签: asp.net-web-api2 swagger

我正在开发支持多个版本的webapi。目前我有三个版本1.0,1.1和2.0。我已经完成了swagger的多版本支持解决方案,并通过以下链接实现了它

swagger not working properly with multiversions

代码工作正常但问题是swagger没有加载版本1.1。它适用于版本1.0和2.0。 enter image description here

enter image description here

提前致谢。

2 个答案:

答案 0 :(得分:0)

找出解决方案。这是由于swagger.config实例问题。通过在swagger.config中添加程序集[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]并将所有版本控制代码移动到webapi.config来解决此问题。不知道为什么必须要为次要版本工作,但它对我有用。

答案 1 :(得分:0)

对我来说,http://localhost:64754/swagger/docs/v1.1http://localhost:64754/swagger/docs/v1正常工作时,http://localhost:64754/swagger/docs/v2将返回404错误。

我解决的方法是将其添加到web.config

<system.webServer>
    <modules>
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
    </modules>
    ...
</system.webServer>
相关问题