Share via

how to set the signalr use XMLHttpRequest not use others.

mc 7,186 Reputation points
2023-06-11T01:19:27.05+00:00

I just want to use XMLHttpRequest

Developer technologies | ASP.NET Core | Other
0 comments No comments

Answer accepted by question author

AgaveJoe 31,361 Reputation points
2023-06-11T11:05:22.96+00:00

SignalR falls back to long polling if a web socket connection cannot be made. Long polling uses AJAX and I think this is what you're asking.

Please read the official documentation which illustrates how to configure transport mode in an ASP.NET core application.

ASP.NET Core SignalR configuration

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 84,071 Reputation points
    2023-06-12T01:18:30.4666667+00:00

    to only use XMLHttpRequest, you configure the hub connection to only use the long polling transport:

    var connection = new HubConnectionBuilder()
        .WithUrl(myUrl, HttpTransportType.LongPolling)
        .Build();
    
    

    not sure why you want to do this. it has more processing overhead than web socket, and fallback is supported.

    also The signalr server does not support long polling by default. You will need to enable:

    app.MapHub<ChatHub>("/chathub", options =>
    {
        options.Transports =
            HttpTransportType.WebSockets |
            HttpTransportType.LongPolling;
    });
    

    I believe azure signal/r only supports the web sockets transport.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.