在这里我有一个小问题,我想找出正在访问我的网站的客户端的 IP 地址,我尝试了很多但所有这些都给了我 127.0.0.1 作为 IP,而我正在本地主机上进行测试,
请有人提供代码片段并帮助我,
提前致谢,
public string GetClientIP()
{
string result = string.Empty;
string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
string[] ipRange = ip.Split(',');
int le = ipRange.Length - 1;
result = ipRange[0];
}
else
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
return result;
}