Inside your hub you can read IHttpConnectionFeature
features like:
using Microsoft.AspNetCore.Http.Features;
...
var feature = Context.Features.Get<IHttpConnectionFeature>();
It will return an instance of IHttpConnectionFeature
with the following properties:
public interface IHttpConnectionFeature
{
//
// Summary:
// The unique identifier for the connection the request was received on. This is
// primarily for diagnostic purposes.
string ConnectionId { get; set; }
//
// Summary:
// The IPAddress of the client making the request. Note this may be for a proxy
// rather than the end user.
IPAddress? RemoteIpAddress { get; set; }
//
// Summary:
// The local IPAddress on which the request was received.
IPAddress? LocalIpAddress { get; set; }
//
// Summary:
// The remote port of the client making the request.
int RemotePort { get; set; }
//
// Summary:
// The local port on which the request was received.
int LocalPort { get; set; }
}
Code example:
public override Task OnConnectedAsync()
{
var feature = Context.Features.Get<IHttpConnectionFeature>();
_logger.LogInformation("Client connected with IP {RemoteIpAddress}", feature.RemoteIpAddress);
return base.OnConnectedAsync();
}