C# 从信号器连接获取客户端IP

C# 从信号器连接获取客户端IP,c#,asp.net-core,.net-core,signalr,C#,Asp.net Core,.net Core,Signalr,我知道以前有人问过这个问题。但在此后的8年里,信号员发生了很大的变化 那么,有人知道如何从信号集线器获取客户端的IP吗 我使用SignalR在不同服务器上的两个.net核心应用程序之间进行通信,因此没有HTTP请求或为网站提供服务或类似服务。在您的中心内,您可以阅读IHttpConnectionFeature功能,如: using Microsoft.AspNetCore.Http.Features; ... var feature = Context.Features.Get<IHttp

我知道以前有人问过这个问题。但在此后的8年里,信号员发生了很大的变化

那么,有人知道如何从信号集线器获取客户端的IP吗


我使用SignalR在不同服务器上的两个.net核心应用程序之间进行通信,因此没有HTTP请求或为网站提供服务或类似服务。

在您的中心内,您可以阅读
IHttpConnectionFeature
功能,如:

using Microsoft.AspNetCore.Http.Features;
...
var feature = Context.Features.Get<IHttpConnectionFeature>();
代码示例:

public override Task OnConnectedAsync()
{
     var feature = Context.Features.Get<IHttpConnectionFeature>();
     _logger.LogInformation("Client connected with IP {RemoteIpAddress}", feature.RemoteIpAddress);
     return base.OnConnectedAsync();
}
公共覆盖任务OnConnectedAsync()
{
var feature=Context.Features.Get();
_logger.LogInformation(“与IP连接的客户端{RemoteIpAddress}”,feature.RemoteIpAddress);
返回base.OnConnectedAsync();
}

在集线器内,您可以阅读
IHttpConnectionFeature
功能,如:

using Microsoft.AspNetCore.Http.Features;
...
var feature = Context.Features.Get<IHttpConnectionFeature>();
代码示例:

public override Task OnConnectedAsync()
{
     var feature = Context.Features.Get<IHttpConnectionFeature>();
     _logger.LogInformation("Client connected with IP {RemoteIpAddress}", feature.RemoteIpAddress);
     return base.OnConnectedAsync();
}
公共覆盖任务OnConnectedAsync()
{
var feature=Context.Features.Get();
_logger.LogInformation(“与IP连接的客户端{RemoteIpAddress}”,feature.RemoteIpAddress);
返回base.OnConnectedAsync();
}

谢谢你。正是我想要的:)谢谢你。正是我想要的:)