在 dotnet core web api ::ffff:127.0.0.1 中获取客户端 IP 地址
Getting client IP address in dotnet core web api ::ffff:127.0.0.1
我试图在我的 dotnet 核心网络 api 中获取客户端(网络调用者 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 地址?
您似乎在 IIS 上托管您的应用程序,在防火墙、NAT、Apache 路由等后面。检查您在请求中获得的 headers 列表。如果请求已被转发,IP 地址可能是其中之一。您可能还想看看这个答案:https://whosebug.com/a/62060533/9890829
我试图在我的 dotnet 核心网络 api 中获取客户端(网络调用者 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 地址?
您似乎在 IIS 上托管您的应用程序,在防火墙、NAT、Apache 路由等后面。检查您在请求中获得的 headers 列表。如果请求已被转发,IP 地址可能是其中之一。您可能还想看看这个答案:https://whosebug.com/a/62060533/9890829