SignalR响应覆盖标头 [英] SignalR responses overwriting headers

查看:106
本文介绍了SignalR响应覆盖标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个简单的SignalR集线器,该集线器位于WebAPI服务中,并且在WebAPI和SignalR上都包含了所有必需的CORS属性.我的WebAPI端点都按预期工作,但SignalR却无法正常工作.

I've built a simple SignalR hub that lives within a WebAPI service, I've included all the required CORS attributes on both WebAPI and SignalR. My WebAPI endpoints are all working as expected but SignalR isn't.

我已经尝试了所有可以想到的内容,并且可以在网上找到所有内容,但是没有任何效果,我已经尝试了此答案,然后其他解决之道.

I've tried all I can think of and all I can find online but nothing works, I already tried this answer, and this other to no solution.

我的SignalR扩展方法如下

My SignalR extension method looks like this

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在所有请求上添加响应标头,但我总是遇到相同的错误:

And I even tried adding the response headers on all requests using the Web.config but I allways get the same error:

XMLHttpRequest无法加载>://://MyApplicationServer/notifications/signalr/negotiate? clientProtocol = 1.5& access_token = & connectionData =.当凭据标志为true时,不能在'Access-Control-Allow-Origin'标头中使用通配符'*'.因此,不允许访问源"MyOriginService". XMLHttpRequest的凭据模式由withCredentials属性控制.

XMLHttpRequest cannot load https://MyApplicationServer/notifications/signalr/negotiate?clientProtocol=1.5&access_token=&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.

推荐答案

经过更多研究并摆弄问题的服务器端之后,我遇到了此GitHub问题,请求的"withCredentials"参数始终设置为'真的'.解决方案是在客户端上调用start方法,如下所示:

After more research and fiddling with the server side of the problem, I ran into this answer and found the error to be with the client side of the request. according to this GitHub issue, the "withCredentials" parameter of the request is always set to 'true'. The solution was to call on the client the start method as follows:

$.connection.hub.start({ withCredentials: false }).done(function () {  //... }

这篇关于SignalR响应覆盖标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆