title: SignalR connection failed when not on localhost
body: <p>Using Blazor as the client. NET 6 on both client and server.</p>
  <p>I've already been trying any possible workaround for hours to this and I'm stuck.
  The clientside and serverside are on the same server (wasm backed) but the thing It doesn't work when it tries to connect to the server through a remote domain, not localhost, which worked on the development stage.</p>
  <p>I've been wondering about CORS but I have my CORS properly set and still the same, even if I call the AddAuthentication method. Also, I have tried to enable the Websocket service in additional features at IIS. Note I'm running this on the server with dotnet publish.</p>
  <p><strong>Client-side console:</strong>
  <a href="https://i.stack.imgur.com/xGp1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xGp1R.png" alt="enter image description here" /></a></p>
  <p><strong>Client-side websocket details:</strong>
  <a href="https://i.stack.imgur.com/BxHIb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BxHIb.png" alt="enter image description here" /></a></p>
  <p>Relevant server-side settings on server that may affect this:</p>
  <p>In appsettings.json:</p>
  <pre><code>    {
    &quot;Kestrel&quot;: {
      &quot;EndPoints&quot;: {
        &quot;Http&quot;: {
          &quot;Url&quot;: &quot;https://0.0.0.0:443&quot;
        }
      }
    },
  </code></pre>
  <p>In Startup/Program</p>
  <pre><code>// CORS (before SignalR)
  builder.Services.AddCors(options =&gt;
      options.AddDefaultPolicy(builder =&gt; builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
  
  //Add SignalR
  builder.Services.AddSignalR(opt =&gt; { opt.EnableDetailedErrors = true; opt.HandshakeTimeout = TimeSpan.FromSeconds(120); }); ;
  builder.Services.AddResponseCompression(opt =&gt;
      {
          opt.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { &quot;application/octet-stream&quot; });
      });
  
  
  // SignalR response compression
  app.UseResponseCompression();
  
  // log requests statuses in console
  
  if (true)
  {
      app.Use(async (context, next) =&gt;
      {
          await next.Invoke();
          Console.WriteLine(
              $&quot;{DateTime.Now.Hour} : {DateTime.Now.Minute} : {DateTime.Now.Second} - response: {context.Response.StatusCode}&quot;);
      });
  }
  
  // Handles exceptions and generates a custom response body
  app.UseExceptionHandler(&quot;/errors/500&quot;);
  
  
  // Handles non-success status codes with empty body
  app.UseStatusCodePagesWithReExecute(&quot;/errors/{0}&quot;);
  
  app.UseHttpsRedirection();
  
  app.UseBlazorFrameworkFiles();
  app.UseStaticFiles();
  
  // CORS
  app.UseCors();
  
  app.UseRouting();
  
  app.UseAuthentication();
  app.UseAuthorization();
  
  app.MapControllers();
  
  // Blazor
  app.MapFallbackToFile(&quot;index.html&quot;);
  
  // Map SignalR Hubs
  app.UseEndpoints(endpoints =&gt;
  {
      endpoints.MapHub&lt;SmsHub&gt;(&quot;/smshub&quot;);
  });
  </code></pre>
  <p>Multiple 204 status codes logged on the server (because of this), which should not be happening:
  <a href="https://i.stack.imgur.com/jO6n6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jO6n6.png" alt="enter image description here" /></a></p>
  <p><strong>IMPORTANT NOTE:</strong> as you can notice, in some instance, the Hub's OnConnectedAsync is called and logged with the info user provides. Maybe in some of the different methods that are attempted to connect to the socket, but closing the browser window will not end that connection until it times out. Finally, I want to add this live-server example is using the Cloudflare proxy, but it's nothing related to it.</p>
  <p>I will award the valid reply. Thank you.</p>