.net core 5 signalr cors 被通配符阻塞

.net core 5 signalr cors blocked with wildcard

为什么不工作允许 all cors?

.net 核心 5 网络 api:

   services.AddCors();
   services.AddSignalR();


   app.UseCors(c => c.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

js文件:

import * as signalR from '@microsoft/signalr'

let connection = new signalR.HubConnectionBuilder()
    .withUrl("https://localhost:5001/ws/candlehub")
    .build();

connection.start()
    .then(() => connection.invoke("ConnectToCandle", "x"));

错误:

https://docs.microsoft.com/aspnet/core/signalr/security?view=aspnetcore-5.0#cross-origin-resource-sharing

默认情况下,javascript 客户端使用 withCredentials = true,根据 CORS 规范,它不适用于 * 来源。您应该指定您想要允许的显式来源并在您的 CORS 配置中包含 AllowCredentials(),或者在 HubConnectionBuilder 选项上设置 withCredentials = false