I get server IP Address instead of client IP by using below method in ASP.NET CORE Web API .
Please tell me where I'm going wrong. I have used ServerVariables["HTTP_X_FORWARDED_FOR"] in asp mvc before and that has worked correctly.
private string DetectIPAddress(HttpRequest request)
{
var _IP = "RemoteIp:" + request.HttpContext.Connection.RemoteIpAddress.ToString() + " - LocalIpAddress:" +
request.HttpContext.Connection.LocalIpAddress;
try
{
_IP += " IP.AddressFamily:" + Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString();
_IP += " HostName:" + Dns.GetHostEntry(Dns.GetHostName()).HostName;
}
catch (Exception e)
{
}
return _IP;
}