Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR responses overwriting headers

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.

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;
    }

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

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.

like image 503
evilpilaf Avatar asked Apr 14 '16 22:04

evilpilaf


1 Answers

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 () {  //... }
like image 91
evilpilaf Avatar answered Oct 03 '22 02:10

evilpilaf