[英]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 存储库中的这两页放在一起,完成您所要求的简单方法是:
.EnableSwagger(c =>
{
c.RootUrl(req => req.ComputeHostAsSeenByOriginalClient());
...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.