【问题标题】:Swagger not supporting minor versions ASP.NET WebapiSwagger 不支持次要版本 ASP.NET Webapi
【发布时间】:2018-02-19 13:25:42
【问题描述】:

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

swagger not working properly with multiversions

代码运行良好,但问题是 1.1 版没有加载 swagger。它适用于 1.0 和 2.0 版本。

提前致谢。

【问题讨论】:

  • http://localhost:64754/swagger/docs/v1.1 真的存在吗?例如。如果您在浏览器中导航到此 URL,您能看到它吗?
  • 是的,我可以导航到 bowser 中的 url

标签: asp.net-web-api2 swagger


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    我修复它的方法是将其添加到web.config

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

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2016-04-26
      • 2014-06-08
      • 2013-12-30
      • 1970-01-01
      • 2012-06-19
      • 2020-10-04
      相关资源
      最近更新 更多