内容目录
In SignalR, to obtain the client's connection information, you can use IHttpConnectionFeature
to retrieve the client's communication IP and port.
// Get the service
var feature = Context.Features.Get<IHttpConnectionFeature>();
var httpContext = Context.GetHttpContext();
ArgumentNullException.ThrowIfNull(feature);
ArgumentNullException.ThrowIfNull(httpContext);
// Header query information
var clientIdSV = httpContext.Request.Headers["ClientId"];
var clientId = clientIdSV.FirstOrDefault();
ArgumentNullException.ThrowIfNull(clientId);
// Get the client's communication address
var remoteAddress = feature.RemoteIpAddress;
ArgumentNullException.ThrowIfNull(remoteAddress);
var remotePort = feature.RemotePort;
If you want to get the client's Hub ConnectionId
, you can use
base.Context.ConnectionId
文章评论