IIS上的SignalR握手超时

时间:2018-12-06 19:45:44

标签: angular asp.net-core iis-7 signalr asp.net-core-2.1

环境:

  • Windows 7 Home上的IIS 7.0
  • 用asp.net core 2.1编写的WebService
  • 用Angular编写的WebClient
  • 最新的signalR库(.NET Core和JS)

问题:

  • 握手请求因15秒超时而失败。服务器的唯一响应是No Connection with that ID。但是有时它会在4毫秒内连接,这很奇怪(重新连接之间有10秒的延迟)。

其他信息:

  • 也可以从外部访问IIS(比方说www.myapp.domain.com:88/application,信号中心Hub:www.myapp.domain.com:88/application/appHub),但这似乎无关紧要,因为当我仅使用内部IP时也会出现问题。
  • 在IIS上,任何其他请求都可以正确,快速地工作,唯一的问题是与signalR连接有关。
  • 由于回退,它使用SSE。
  • 在开发环境(茶est)上,一切正常。
  • 所有防火墙等都已关闭

.Net Core:

public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
        {
            builder.AllowAnyHeader()
                .AllowAnyMethod()
                .AllowAnyOrigin()
                .AllowCredentials();
        }));
        services.AddSignalR(hubOptions =>
        {
            hubOptions.EnableDetailedErrors = true;
            hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(10);
            hubOptions.HandshakeTimeout = TimeSpan.FromSeconds(5);
        });
        services.AddMvc(options =>
            {
                options.Filters.Add(new ProducesAttribute("application/json"));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddControllersAsServices();
        services.AddAuthentication(Configuration);
        services.AddAuthorizationPolicies();

        return ServiceProviderFactory.CreateAutofacServiceProvider(services, Configuration);
    }

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }

        app.UseCors("CorsPolicy");
        app.UseAuthentication();
        app.UseExceptionHandler(env);
        app.UseWebSockets();
        app.UseHubs();
        app.UseMvc();
    }

JS:

private buildConnection() {
    const connectionBuilder = new HubConnectionBuilder();
    this.hubConnection = connectionBuilder
        .withUrl(environment.hubUrl, { accessTokenFactory: () => this.accessToken() })
        .configureLogging(LogLevel.Trace)
        .build();
}

(敏感数据被删除) enter image description here

0 个答案:

没有答案