asp.net-web-api – SignalR响应覆盖标头

我已经在一个WebAPI服务中构建了一个简单的SignalR集线器,我在WebAPI和SignalR上都包含了所有必需的CORS属性.我的WebAPI端点都按预期工作,但SignalR不是.

我已经尝试了所有我能想到的和我在网上找到的所有内容但没有任何作用,我已经尝试过this answerthis other没有解决方案.

我的SignalR扩展方法如下所示

public static IAppBuilder UseSignalrNotificationService(this IAppBuilder app)
    {
        var config = new HubConfiguration();
        config.Resolver = new HubDependencyResolver();
        config.EnableDetailedErrors = true;
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR(config);

        return app;
    }

我甚至尝试使用Web.config在所有请求上添加响应头但我总是得到相同的错误

XMLHttpRequest cannot load 07002&connectionData=. A wildcard ‘*’ cannot be used in the ‘Access-Control-Allow-Origin’ header when the credentials flag is true. Origin ‘MyOriginService’ is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

解决方法

经过更多研究和摆弄问题的服务器端,我遇到了 this answer并发现错误与客户端的请求有关.根据 this GitHub issue,请求的“withCredentials”参数始终设置为“true”.解决方案是在客户端上调用start方法,如下所示:
$.connection.hub.start({ withCredentials: false }).done(function () {  //... }

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....