Set an ASP.NET Core SignalR Client’s Proxy Before Startup
Configure an ASP.NET Core SignalR client through HttpConnectionOptions so its negotiation and selected transport have the intended route.
Before starting an ASP.NET Core SignalR client, configure its connection options:
var connection = new HubConnectionBuilder()
.WithUrl("https://events.example/hub", options =>
{
options.Proxy = new WebProxy("http://proxy.example:8080");
})
.Build();
This fragment uses the modern SignalR client and System.Net. Manage connection through the application's async lifecycle; keep the hub URL as the destination. For a permitted public hub test with no proxy credentials configured, the HTTP proxy list supplies candidate HTTP intermediaries.
| Transport setup | Where the proxy applies |
|---|---|
| Default connection behavior | HttpConnectionOptions.Proxy selects the intermediary; .NET 8's default WebSocket transport also assigns it to ClientWebSocketOptions |
HttpMessageHandlerFactory | Customizes HTTP handling, not WebSocket connections |
A supplied WebSocketFactory | Owns its creation behavior and must apply its required route |
A successful negotiation does not prove the later WebSocket tunnel was accepted. If a custom WebSocketFactory uses .NET ClientWebSocket, configure that socket’s proxy before connecting. Read transport diagnostics for the last completed step and inspect any deliberate fallback transport too.
Older ASP.NET SignalR examples setting Connection.Proxy belong to another generation. With HubConnectionBuilder, keep the proxy with the other WithUrl transport options rather than configuring an unrelated HTTP request.