skip to content

Your SignalR hub's users sit behind a corporate proxy that blocks WebSockets. What happens, and how do Transports and SkipNegotiation change it?

level: middleimportance: should knowfreq 38%

answer

  1. the WebSocket attempt fails, fallback follows
  2. options.Transports in MapHub
  3. client transport option narrows its own list
  4. skipNegotiation only with WebSockets
  5. no negotiate, no fallback

basics

~20 s

With defaults the WebSocket attempt fails and the client falls back to Server-Sent Events or long polling, so the hub keeps working, just less efficiently. Restricting transports to WebSockets, or skipping negotiation, removes that fallback, and those users cannot connect at all.

solid answer

~50 s

Negotiate is an ordinary `POST`, so it passes the proxy; the WebSocket upgrade is then refused, the JavaScript client logs that the WebSockets transport failed to start and tries Server-Sent Events, then long polling, which looks like plain HTTP to almost any proxy. Users get a working hub with more requests and latency. The server can narrow the list with `MapHub<QuotesHub>("/hubs/quotes", o => o.Transports = ...)`, and the client with `withUrl(url, { transport: ... })`; the effective set is the intersection. `skipNegotiation: true` (`SkipNegotiation` in the .NET client) drops the negotiate round trip, but only with the WebSockets transport alone; anything else throws "Negotiation can only be skipped when using the WebSocket transport directly." With negotiation skipped there is no list to fall back on, so users behind the proxy fail every time. For an audience behind corporate proxies, keep negotiation and the fallback, and measure which transport clients end up using.

code

csharp · 5 lines
csharp
app.MapHub<QuotesHub>("/hubs/quotes", options =>
{
    // Server-Sent Events stall behind the buffering proxy; keep one HTTP fallback.
    options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling;
});

go deeper

for a junior

Remember that SignalR falls back from WebSockets to Server-Sent Events and long polling by itself, so a blocked WebSocket usually means a slower connection, not a broken one.

for a middle

Explain how server and client transport settings intersect, and why skipNegotiation is legal only with WebSockets and removes the fallback.

for a senior

Diagnose a proxy problem from the transports clients settle on, keep one HTTP fallback for proxied users, and watch proxy timeouts against the long-polling hold time.

for a principal

Set a transport policy per audience: WebSockets-only with skipped negotiation for networks you control, fallback for everyone else, and the monitoring to know which is which.

## What the proxy breaks Picture a market-quotes hub used by staff whose traffic leaves through a corporate proxy that refuses WebSocket upgrades. With default options: 1. **Negotiate succeeds.** `POST /hubs/quotes/negotiate?negotiateVersion=1` is an ordinary HTTP request, so the proxy forwards it and the server offers WebSockets, Server-Sent Events and long polling. 2. **WebSockets fail.** The upgrade request is blocked or answered without `101 Switching Protocols`. The client logs that the `WebSockets` transport failed to start. 3. **Server-Sent Events are tried.** They use a normal long-lived `GET`. A proxy that buffers whole responses can hold the events back, in which case this transport fails or stalls too. 4. **Long polling works.** Each poll and each send is a short, ordinary request. The hub, the hub methods and the client code are unchanged; the cost is more requests and more latency per message. ## Restricting transports Both ends can narrow the set, and the connection uses the intersection: | Where | How | Effect | |---|---|---| | Server | `MapHub<QuotesHub>("/hubs/quotes", o => o.Transports = HttpTransportType.WebSockets \| HttpTransportType.LongPolling)` | negotiate offers only these | | JavaScript client | `withUrl(url, { transport: HttpTransportType.WebSockets \| HttpTransportType.LongPolling })` | the client tries only these | | .NET client | `WithUrl(url, o => o.Transports = ...)` | same, for .NET callers | A restriction is useful for removing a transport you cannot support, for example Server-Sent Events through a buffering proxy, while keeping one fallback. Restricting to WebSockets alone shuts out every user behind this proxy. If the two sets do not overlap, the JavaScript client fails with "None of the transports supported by the client are supported by the server." ## SkipNegotiation `skipNegotiation: true` in the JavaScript client, or `HttpConnectionOptions.SkipNegotiation` in the .NET client, makes the client open the WebSocket directly, with no negotiate request: - **Allowed only with WebSockets alone.** With any other transport setting the client throws "Negotiation can only be skipped when using the WebSocket transport directly." - **Saves a round trip** on every connect and reconnect. - **Removes the fallback.** No negotiate response means no list of alternatives; if the upgrade fails, the connection fails. - **Skips the negotiate redirect** that Azure SignalR Service uses to send clients to the service. Behind a proxy that blocks WebSockets, a client with negotiation skipped can never connect, however often it retries. ## Choosing for this audience - Keep negotiation and at least one HTTP fallback for anyone who may sit behind a corporate proxy. - Reserve WebSockets-only with skipped negotiation for clients whose network you control, such as a service talking to another service. - Log `IHttpTransportFeature.TransportType` per connection; a rising share of long polling is the first sign that a network change is blocking upgrades. - Long polling holds each poll for up to `LongPollingOptions.PollTimeout`, 90 seconds by default, so proxy read timeouts below that can cut polls short. ## Tokens on the fallback path With bearer tokens, long-polling requests and Server-Sent Events sends go out as ordinary HTTP requests with an `Authorization` header. Only browser WebSocket and `EventSource` requests carry the token in the `access_token` query value, so the fallback does not change how the server authenticates these users.

  • What does a SignalR client do if the server's Transports option and its own transport option share no transport?
    Negotiate returns only the server's transports, the client filters them by its own setting, and nothing is left. The JavaScript client then rejects `start()` with "None of the transports supported by the client are supported by the server." The fix is to make the two sets overlap, usually by removing the client-side restriction.
  • Why might Server-Sent Events fail behind the same proxy even though they use a plain GET?
    Server-Sent Events depend on the response being streamed to the browser as events arrive. A proxy that buffers whole responses, or holds them until they finish, never passes the events through in time, so the transport stalls or fails and the client moves on to long polling.

  • skipNegotiation: true works with any transport and simply saves a round trip.
  • When WebSockets are blocked, the hub is unusable unless client code catches the error and retries with long polling.
  • Setting transport on the JavaScript client is enough to stop the server accepting long polling.
  • Skipping negotiation keeps the transport fallback; it only removes the negotiate request.