微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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 () {  //... }

原文地址:https://www.jb51.cc/aspnet/246814.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐