C# 获取客户端计算机的IP地址而不是服务器IP(通过服务器的IP地址访问)

C# 获取客户端计算机的IP地址而不是服务器IP(通过服务器的IP地址访问),c#,ip-address,C#,Ip Address,我需要获取客户端计算机的IP地址,而不是服务器IP。使用C# 我已经做了研究,但没有找到正确的答案。 我试过了 string strHostName = System.Net.Dns.GetHostName(); string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString(); HttpContext.Current.Request.UserHostAddress;

我需要获取客户端计算机的IP地址,而不是服务器IP。使用C#

我已经做了研究,但没有找到正确的答案。 我试过了

string strHostName = System.Net.Dns.GetHostName();
    string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

HttpContext.Current.Request.UserHostAddress;
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
这些对我都不管用


我还尝试了javascript,将IP地址放在控件中,工作正常。但是,在页面加载事件上执行时,不会捕获控件值。

搜索是最佳答案,有时是。我要四个小时。他们都说了同样的话。对我不起作用。我尝试了这个
字符串strHostName=HttpContext.Current.Request.UserHostAddress.ToString();IPAddress=System.Net.Dns.GetHostAddresses(strHostName).GetValue(0.ToString()但是它得到了网络的ip