Reputation: 40092
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?
Upvotes: 2
Views: 2108
Reputation: 2397
https://stackoverflow.com/a/53577064/2068719
// using Microsoft.AspNetCore.Http.Connections.Features;
var transportType = Context.Features.Get<IHttpTransportFeature>().TransportType;
Upvotes: 1
Reputation: 979
To get Signalr TransportType.
Context.Features.Get<IHttpTransportFeature>().TransportType.ToString()
Upvotes: 2
Reputation: 342
You can get the transport type from the HubCallerContext like so
Context.Items[ConnectionMetadataNames.Transport]
Upvotes: 1