Search code examples
signalrasp.net-core-signalr

Determine transport method in SignalR Core?


In SignalR 2.0 the transport method can be determined by the transport parameter in the query string.

string transportMethod = queryString["transport"];

This doesn't seem to be the case in SignalR for ASP.NET Core.

The best I can do, it seems, is to use header information.

For WebSocket connections:

Connection = Upgrade
Upgrade = Websocket

And long polling:

Connection = Keep-Alive

And server-sent events:

Connection = Keep-Alive
Accept = text/event-stream

Is there a better/easier way to go about determining the transport method?


Solution

  • You can get the transport type from the HubCallerContext like so

     Context.Items[ConnectionMetadataNames.Transport]