【发布时间】:2020-12-09 10:23:37
【问题描述】:
我正在尝试在我的 dotnet core web api 中获取客户端(web api 的调用者)IP 地址。我从不同的客户端网络测试 IP 地址为“::ffff:127.0.0.1”。本地主机获取为“::::1” 我在我的操作方法中使用以下代码:
var ipaddress = HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();
也尝试过以下代码:
var ipaddress = Request.HttpContext.Connection.RemoteIpAddress;
得到相同的结果。我们如何在 dotnet core web api 中获取准确的 IP 地址?
【问题讨论】:
标签: asp.net-core-webapi webapi