title: SignalR handshake timeout on IIS
body: <p><strong>Environment:</strong> </p>
  
  <ul>
  <li>IIS 7.0 on Windows 7 Home</li>
  <li>WebService written in asp.net core 2.1</li>
  <li>WebClient written in Angular</li>
  <li>Latest signalR library(.NET Core and JS)</li>
  </ul>
  
  <p><strong>Issue:</strong></p>
  
  <ul>
  <li>Handshake request fails because of 15s timeout. The only response from server is <code>No Connection with that ID</code>. But sometimes it will connect in 4ms, which is completely strange(There is 10s delay between reconnections).</li>
  </ul>
  
  <p><strong>Additional info:</strong></p>
  
  <ul>
  <li>IIS is also accessible from outside (let's say <code>www.myapp.domain.com:88/application</code>, signalr Hub: <code>www.myapp.domain.com:88/application/appHub</code> ) but it seems to be irrelevant because issue occurs also when I'm using only internal IPs.</li>
  <li>On IIS any other request works correctly and fast, the only issue is with signalR connections.</li>
  <li>Because of fallback it uses SSE.</li>
  <li>On development environment(kestrel) everything works fine.</li>
  <li>Every firewall etc. is turned off</li>
  </ul>
  
  <p><strong>.Net Core:</strong> </p>
  
  <pre><code>public IServiceProvider ConfigureServices(IServiceCollection services)
      {
          services.AddCors(options =&gt; options.AddPolicy("CorsPolicy", builder =&gt;
          {
              builder.AllowAnyHeader()
                  .AllowAnyMethod()
                  .AllowAnyOrigin()
                  .AllowCredentials();
          }));
          services.AddSignalR(hubOptions =&gt;
          {
              hubOptions.EnableDetailedErrors = true;
              hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(10);
              hubOptions.HandshakeTimeout = TimeSpan.FromSeconds(5);
          });
          services.AddMvc(options =&gt;
              {
                  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();
      }
  </code></pre>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>private buildConnection() {
      const connectionBuilder = new HubConnectionBuilder();
      this.hubConnection = connectionBuilder
          .withUrl(environment.hubUrl, { accessTokenFactory: () =&gt; this.accessToken() })
          .configureLogging(LogLevel.Trace)
          .build();
  }
  </code></pre>
  
  <p>(Sensitive data is erased)
  <a href="https://i.stack.imgur.com/Fejzh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fejzh.png" alt="enter image description here"></a></p>