简体   繁体   English

WebApi Swagger (Swashbuckle) - 通过代理连接时无法访问 Swagger UI

[英]WebApi Swagger (Swashbuckle) - can't access Swagger UI when connecting through proxy

I have a swagger (Swashbuckle) enabled on one of my API controllers.我在我的一个 API 控制器上启用了 swagger(Swashbuckle)。

Server sits on http://192.168.7.119:1001 and Swagger UI is accessed through http://192.168.7.119:1001/swagger .服务器位于http://192.168.7.119:1001和 Swagger UI 通过Z80791B3AE7002CB88C246876D9FAA8F718.://1902.016 .

When connecting locally, everything is fine and I can access Swagger UI on port 1001 as expected.在本地连接时,一切都很好,我可以按预期访问端口 1001 上的 Swagger UI。 But when trying connect throug proxy on port 1000 (which redirects 1000 to 1001), I get a well known error:但是当尝试在端口 1000 上连接代理(将 1000 重定向到 1001)时,我收到了一个众所周知的错误:

"Can't read from server. It may not have the appropriate access-control-origin settings". “无法从服务器读取。它可能没有适当的访问控制来源设置”。

I have read this:我读过这个:

Unable to access swagger despite cors enabled Asp.NET WebAPI 尽管启用了 cors Asp.NET WebAPI,但仍无法访问 swagger

and tried to set the RootUrl manually in Startup file, within Swagger like this:并尝试在启动文件中手动设置 RootUrl,在 Swagger 中,如下所示:

.EnableSwagger(c => 
         {
             c.RootUrl(req => @"http://192.168.7.119:1001";
             ...
         });

CORS settings are set as: CORS 设置为:

appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

Any hints what am I doing wrong here?任何提示我在这里做错了什么?

Putting together this two pages from github repos of Swashbuckle the easy way to do what you're asking is:将 Swashbuckle 的 github 存储库中的这两页放在一起,完成您所要求的简单方法是:

  • From Github Make sure that your proxy is sending the X-Forwarded-* headers (Apache does it out of the box while Nginx doesn't seems so. You have to do some changes on the nginx conf . 从 Github确保您的代理正在发送 X-Forwarded-* 标头(Apache 开箱即用,而 Nginx 似乎并非如此。您必须对ZEE434023CF89D7DFB21F63FDD74F进行一些更改。
  • From Github . 来自 Github Create this HttpRequestMessageExtensions static class with the ComputeHostAsSeenByOriginalClient method and then使用ComputeHostAsSeenByOriginalClient方法创建此 HttpRequestMessageExtensions static class 然后
.EnableSwagger(c => 
         {
               c.RootUrl(req => req.ComputeHostAsSeenByOriginalClient());
             ...
         });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可以从Swashbuckle / Swagger UI中排除ASP.NET WebAPI操作参数吗? - Can an ASP.NET WebAPI action parameter be excluded from Swashbuckle/Swagger UI? 迁移到 Swashbuckle.AspNetCore 版本 5 时,Swagger UI 中的不记名身份验证 - Bearer authentication in Swagger UI, when migrating to Swashbuckle.AspNetCore version 5 我可以配置Swagger UI以使用Swashbuckle接受并清空数组吗? - Can I configure Swagger UI to accept and empty array using Swashbuckle? Swagger UI和ASP.NET-找不到映射异常-无法访问Swagger UI页面 - Swagger UI and ASP.NET - Mapping not found exception - can't access swagger UI page Swashbuckle 中的默认 Swagger UI URL 是什么? - What is the default Swagger UI URL in Swashbuckle? 将身份验证添加到/ swagger / ui / index页面 - Swagger | Web API | Swashbuckle - Add Authentication to /swagger/ui/index page - Swagger | Web API | Swashbuckle 如何在swagger / swashbuckle WebAPI 2中定义响应错误元数据 - How to define response error metadata in swagger/swashbuckle WebAPI 2 Swashbuckle Swagger C#WebApi Core 2.0-“产品”为空 - Swashbuckle Swagger C# WebApi Core 2.0 - “Produces” is empty 不要在 Swashbuckle (Swagger) 中显示端点 - Don't show endpoints in Swashbuckle (Swagger) 如何使用 Swashbuckle 省略 WebAPI 上 Swagger 文档中的方法 - How to omit methods from Swagger documentation on WebAPI using Swashbuckle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM