asp.net-mvc - Swashbuckle Swagger url 从 http 到 https .NET
问题描述
我的 API 是在 ASP.NET 中开发的 HTTP API(不是 HTTPS)。
然而,当部署在 DMZ 中时,在网络上的某个地方,不属于我的职责范围内的某些东西只接受 HTTPS 并充当我的 HTTP API 的反向代理。
这导致了招摇的 UI 失礼。
访问 swagger UI 的 URL 是“https://external_public_name/api/swagger/ui/index#/”,但他在绿丝带的文本字段中的一个是“http://external_public_name/api/swagger/docs/ v1”。
因此,页面为空白,控制台出现错误
混合内容:“https://external_public_name/api/swagger/ui/index”页面通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点“http://external_public_name/api/swagger/docs/v1”。此请求已被阻止;内容必须通过 HTTPS 提供。
用 HTTPS 手动替换文本框中的 URL 工作正常。
我应该在哪里更改某些内容以更新该 URL(可能在运行时)?
PS:我已经不得不将 SwaggerConfig.cs 重写为 SwaggerConfig.vb 才能使用它。
Imports System.IO
Imports System.Reflection
Imports System.Web.Http
Imports System.Web.Http.Description
Imports Swashbuckle.Application
Imports Swashbuckle.Swagger
<Assembly: PreApplicationStartMethod(GetType(SwaggerConfig), "Register")>
Public Class SwaggerConfig
Public Class KnownSubTypesDocumentFilter
Implements IDocumentFilter
Public Sub Apply(swaggerDoc As SwaggerDocument, schemaRegistry As SchemaRegistry, apiExplorer As IApiExplorer) Implements IDocumentFilter.Apply
schemaRegistry.GetOrRegister(GetType(BookController.BookList))
End Sub
End Class
Public Shared Sub Register()
Dim thisAssembly = GetType(SwaggerConfig).Assembly
GlobalConfiguration.Configuration.EnableSwagger(
Function(c)
c.Schemes({"https"})
c.SingleApiVersion("v1", "api")
c.DocumentFilter(Of KnownSubTypesDocumentFilter)()
Return c
End Function).EnableSwaggerUi(
Function(ui)
ui.DocumentTitle("Skippy's API")
ui.DocExpansion(DocExpansion.List)
ui.SupportedSubmitMethods()
Return ui
End Function)
End Sub
End Class
解决方案
推荐阅读
- azure-functions - 天蓝色函数 POST 方法是不允许的
- gnuradio - GNU Radio TypeError:primitive_connect():执行简单图时函数参数不兼容
- sql - 提高SQL中同表扣值的性能
- java - 如何添加多个前缀 - JDA
- pytorch - torchvision MNIST HTTPError:HTTP 错误 403:禁止
- arduino - 如何识别和区分 Arduino 中的单击、双击和三次单击?
- sql - 如何使用 params[:sort] 值按联接表列对 ActiveRecord 集合进行排序
- vue.js - Vue 模板与 Vue jsx
- python - 如何在运行配置中传递多个 pytest 命令行选项
- javascript - AJAX 返回整个 html - 我怎样才能只返回一个值?