1

enter image description hereHi everyone my application's Backend in ASP.Net Core 2.0 and Frontend in React Web, I just implemented SignalR But due to issue am not able to create the connection between Client and Server

Error: OPTIONS http://XXXX.XXXX.XXX/chathub/negotiate 405 (Method Not Allowed) XXXX.XXX.XXX/:1 Failed to load http://XXX.XXX.XXX.227/XXXX/chathub/negotiate: Response to the enter image description herepreflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://XX.XXX.XX.XXX:8017' is therefore not allowed access.

Startup File:

services.AddSignalR();

services.AddCors(options =>
            {
                options.AddPolicy(DefaultCorsPolicyName, builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });

Even I also tried with Origin

services.AddCors(options =>
{
          options.AddPolicy(DefaultCorsPolicyName, builder => 
          builder.WithOrigins("http://XXX.XXX.XXX")
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });


app.UseSignalR(route =>
{
     route.MapHub<ChatHub>("/chathub");
});

app.UseCors(DefaultCorsPolicyName); //Enable CORS!

Please help me am stuck with this issue

Thanks,

  • 1
    You have to handle Cors **BEFORE** you handle SignalR. Just put the `UseCors` registration before `UseSignalR`.The middlewares are executed in the order they are registered with `UseXxx` – Tseng Aug 31 '18 at 08:51
  • Possible duplicate of [Response to preflight request doesn't pass access control check](https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check) – Adeel Imran Aug 31 '18 at 10:27

0 Answers0