Access to XMLHttpRequest has been blocked origin ASP.NET CORE 2.2.0 / Angular 8 / signalr1.0.0 [(CORS Policy-Access-Control-Allow-Origin) failed]

前端 未结 2 926
迷失自我
迷失自我 2021-01-20 05:58

nugetPackage on .net core2.2.0:

signalr 1.0.0 + ASP.Core2.2.0

I\'m using angular to connect use signalr:

package.json: \"@aspnet/signalr\": \"1.1.0\

2条回答
  •  醉话见心
    2021-01-20 06:58

    You should add your CORS like this:

    services.AddCors(options =>
    {
        options.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://localhost:4200")
            .AllowAnyHeader()
            .AllowAnyMethod()
            .AllowCredentials()
            .SetIsOriginAllowed((host) => true));
    });
    

    Note:

    The order is important!

提交回复
热议问题