SignalR Core 2.2 CORS AllowAnyOrigin()重大更改

Ale*_*dre 10 c# asp.net-core asp.net-core-signalr asp.net-core-2.2

为了通过SignalR从任何来源连接到ASP.NET Core 2.1服务器,我们必须按以下方式配置管道:

app.UseCors (
  builder => builder
   .AllowAnyHeader ()
   .AllowAnyMethod ()
   .AllowAnyOrigin ()
   .AllowCredentials ()
)
Run Code Online (Sandbox Code Playgroud)

根据文档,ASP.NET Core 2.2不再允许AllowAnyOrigin和AllowCredentials的组合,那么解决方案是什么?而SignalR Core始终在XMLHtppRequest中发送withCredentials:true。

我需要的是,从任何地方开始,无需证书,我们的用户都可以连接到SignalR集线器。

Ale*_*dre 23

有一种解决方法,更改AllowAnyOriginSetIsOriginAllowed

app.UseCors(builder => builder
                .AllowAnyHeader()
                .AllowAnyMethod()
                .SetIsOriginAllowed(_ => true)
                .AllowCredentials()
            );
Run Code Online (Sandbox Code Playgroud)