title: Cross origin request blocked in asp.net core signalR?
body: <p>I am working on asp.net core signalR. I want to make cross domain request.I have a javascript client,when i make hubConnection to cross domain signalR hub, then the below error shows,
  Access to XMLHttpRequest at '<a href="https://localhost:44373/chatHub/negotiate?token=12" rel="nofollow noreferrer">https://localhost:44373/chatHub/negotiate?token=12</a>' from origin '<a href="https://localhost:44381" rel="nofollow noreferrer">https://localhost:44381</a>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.</p>
  
  <p><strong>Javascript client code</strong></p>
  
  <pre><code>var connection = new signalR.HubConnectionBuilder().withUrl("https://localhost:44373/chatHub?token="+12).build();
  </code></pre>
  
  <p><strong>Startup class in cross domain signalr project</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
      {
          // This lambda determines whether user consent for non-essential cookies is needed for a given request.
          options.CheckConsentNeeded = context =&gt; true;
          options.MinimumSameSitePolicy = SameSiteMode.None;
      });
  
      services.AddCors(options =&gt; options.AddPolicy("CorsPolicy", builder =&gt;
      {
          builder
             .AllowAnyMethod()
             .AllowAnyHeader()
             .WithOrigins("*")
             .AllowCredentials();
      }));
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
      services.AddCors();
      services.AddSignalR();
  }
  
  // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }
      else
      {
          app.UseExceptionHandler("/Error");
          // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
          app.UseHsts();
      }
  
      //app.UseCors(builder =&gt;
      //{
      //    builder.WithOrigins("*")
      //       .AllowAnyHeader()
      //       .AllowAnyMethod()
      //       //.WithMethods("GET", "POST")
      //       .AllowCredentials();
      //});
  
      // ... other middleware ...
     // app.UseCors("CorsPolicy");
      app.UseSignalR(routes =&gt;
      {
          routes.MapHub&lt;ChatHub&gt;("/chatHub");
      });
  
      app.UseHttpsRedirection();
      app.UseStaticFiles();
      app.UseCookiePolicy();
  
      app.UseMvc();
  }
  </code></pre>