14

I am using signalr 2.2.2 in an MVC application. Everything works ok apart from the fact, that every time the application navigates to another page a console error in the following form is shown:

XML Parsing Error: no root element found
Location: http://localhost/signalr/abort?transport=serverSentEvents&clientProtocol=1.5&connectionToken=2elX1XZHXH0xmQaLZKyHUFW5Z2rb2DGRYEI...

This only happens in firefox. Does anybody know how to fix this? Thanks

1 Answer 1

1

It might be related to known Firefox-884693 issue. Based on some research (here and here), and searching through SignalR code, a fix would be to assign Content-Type before response is sent back. So following files might have to be changed.

// src/Microsoft.AspNet.SignalR.Core/PersistentConnection.cs
private static Task FailResponse(IResponse response, string message, int statusCode = 400)
{
    response.StatusCode = statusCode;
    // response.ContentType = "text/plain";  // <--- ADD THIS LINE
    return response.End(message);
}


// src/Microsoft.AspNet.SignalR.Core/Transports/WebSocketTransport.cs
private Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
{
    var accept = _context.Environment.Get<Action<IDictionary<string, object>, WebSocketFunc>>(OwinConstants.WebSocketAccept);

    if (accept == null)
    {
        // Bad Request
        _context.Response.StatusCode = 400;
        // _context.Response.ContentType = "text/plain";  // <--- ADD THIS LINE
        return _context.Response.End(Resources.Error_NotWebSocketRequest);
    }

    Action<IWebSocket> prepareWebSocket = socket => {
        _socket = socket;
        socket.OnClose = _closed;
        socket.OnMessage = _message;
        socket.OnError = _error;
    };

    var handler = new OwinWebSocketHandler(callback, prepareWebSocket, _maxIncomingMessageSize);
    accept(null, handler.ProcessRequest);
    return TaskAsyncHelper.Empty;
}

This would require submitting bug to open source project, forking, applying changes, testing it, creating pull request etc. which is longer project than I have time right now. If anyone wants to test this theory, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.