调用HTTPS负载均衡器时SignalRHub出现CORS跨域错误求助
负载均衡场景下SignalR 2.4.3的CORS问题求助
项目基于AngularJS 1.8.2与.NET服务器上的SignalR Hub 2.4.3开发,刚完成从HTTP到HTTPS的迁移。其中一个环境包含两台服务器:一台普通HTTP服务器,一台HTTPS负载均衡器。由于HTTP不安全,我们需要通过负载均衡器访问SignalR Hub,但协商阶段触发了以下CORS错误:
从源'https://stg.fa.lda.com'访问'https://stglb.bo.lda.com/UsersHub/signalr/negotiate?clientProtocol=1.5&AppSourceID=240&connectionData=%5Bname%22userhub%22&_=1713'的XMLHttpRequest已被CORS策略阻止:请求的资源上不存在'Access-Control-Allow-Origin'标头。
其他直接调用普通HTTPS服务器的环境中,协商过程是正常的。我查找了相关解决方案,但大多涉及IConfigureServices(本项目未使用该方式),且很少提及负载均衡的场景。
以下是当前的配置代码:
Startup类配置
public class Startup { public void Configuration(IAppBuilder app) { var idProvider = new CustomUserIdProvider(); GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider); // Branch the pipeline here for requests that start with "/signalr" app.Map("/signalr", map => { // Setup the CORS middleware to run before SignalR. // By default this will allow all origins. You can // configure the set of origins and/or http verbs by // providing a cors options with a different policy. map.UseCors(CorsOptions.AllowAll); var hubConfiguration = new HubConfiguration { // You can enable JSONP by uncommenting line below. // JSONP requests are insecure but some older browsers (and some // versions of IE) require JSONP to work cross domain // EnableJSONP = true }; // Run the SignalR pipeline. We're not using MapSignalR // since this branch already runs under the "/signalr" // path. map.RunSignalR(hubConfiguration); }); } }
WebApi配置
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }
已经配置了允许所有源的CORS,但问题仍未解决。请问针对负载均衡器场景有没有特定的配置方案?
内容的提问来源于stack exchange,提问作者Waldener
相关产品推荐
相关产品推荐

