通过代理转发后,webapi的swagger无法访问,本质原因是代理后url路径发生变化导致/swagger无法定位到json。#https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbucklec.SwaggerEn...

通过代理转发后,webapi的swagger无法访问,本质原因是代理后url路径发生变化导致/swagger无法定位到json。
#https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
相关issue:
https://github.com/microsoft/service-fabric-issues/issues/327
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/662
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/427
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/380
issue评论中,一般推荐通过PreSerializeFilters设置BasePath的方案,但在5.x版本中BasePath被删除了。最终选择使用设置相对路径的方案:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/380#issuecomment-374711180
代码请见 https://github.com/wswind/swagger-under-nginx/blob/f5f6f89cb7f109059f5b4c9524a7ccbb401bc59a/Startup.cs#L56
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "My API V1");
});
本文标题为:asp.net core swagger (Swashbuckle ) 设置nginx proxy后,无法访问的问题


基础教程推荐
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#中的Linq to JSON操作详解 2023-06-08
- C#中 Json 序列化去掉null值的方法 2022-11-18
- Unity shader实现高斯模糊效果 2023-01-16
- C# 解析XML和反序列化的示例 2023-04-14
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- 实例详解C#实现http不同方法的请求 2022-12-26