title: AspNetCore.SignalR 2.1 and CORS
body: <p>I'm migrating our SignalR-Service to the new AspNetCore.SignalR (2.1 preview) and now I get problems with CORS. I will never access the service from the same origin, so I need to disable CORS in general. </p>
  
  <p>I have the folowing CORS policy </p>
  
  <pre><code>services.AddCors(
              options =&gt; options.AddPolicy("AllowCors",
                  builder =&gt;
                  {
                      builder
                          .AllowAnyOrigin()
                          .AllowCredentials()
                          .AllowAnyHeader()
                          .AllowAnyMethod();
                  })
          );
  </code></pre>
  
  <p><em>(My WebApi-Controller calls from a different origin are working fine with these policy)</em></p>
  
  <p>With the old preview package of SignalR for AspNetCore (AspNetCore.SignalR.Server) I don't got any problems but now, my test client got some http-405 which seems like an issue with CORS.</p>
  
  <p>Is there maybe a extra CORS configuration for SignalR, or do I need to allow something else?</p>
  
  <p><strong>Edit</strong>:
  I created a fresh/clean sample project without any special middleware to check If the error happens here and it does.</p>
  
  <p><strong>Sample WebApplication | startup.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Logging;
  using Microsoft.Extensions.Options;
  using WebApplication1.HUBs;
  
  namespace WebApplication1
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddCors(
                  options =&gt; options.AddPolicy("AllowCors",
                      builder =&gt;
                      {
                          builder
                              .AllowAnyOrigin()
                              .AllowCredentials()
                              .AllowAnyHeader()
                              .AllowAnyMethod();
                      })
              );
              services.AddMvc();
              services.AddSignalR(options =&gt;
              {
              });
          }
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseCors("AllowCors");
              app.UseMvc();
              app.UseSignalR(routes =&gt;
              {
                  routes.MapHub&lt;TestHub&gt;("/test");
              });
          }
      }
  }
  </code></pre>
  
  <p><strong>Sample Winforms Application</strong></p>
  
  <pre><code>        private HubConnection _hubConnection;
      private void button1_Click(object sender, EventArgs e)
      {
          var connection = new HubConnectionBuilder().WithUrl("http://localhost:63771/test")
              .WithConsoleLogger()
              .WithTransport(Microsoft.AspNetCore.Sockets.TransportType.WebSockets)
              .Build();
          connection.StartAsync();
      }
  </code></pre>
  
  <p><strong>Sample Winforms Application ConsoleOutput</strong></p>
  
  <pre><code>fail: Microsoft.AspNetCore.Sockets.Client.HttpConnection[8]
     01/10/2018 15:25:45: Failed to start connection. Error getting negotiation response from 'http://localhost:63771/test'.
  System.Net.Http.HttpRequestException: Response status code does not indicate success: 405 (Method Not Allowed).
     bei System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
     bei Microsoft.AspNetCore.Sockets.Client.HttpConnection.&lt;Negotiate&gt;d__42.MoveNext()
  </code></pre>