0

I need to get the IP address of the client's computer not the server IP. using C#

I made research already and nothing provided the right answer. I tried

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"];

none of these worked for me.

I also tried javascript, putting the IP Address in the control and is workingfine. However, the control valu is not being captured when executed on Page Load event.

Json T
  • 65
  • 1
  • 7
  • 1
    Search is best answer, sometimes ^_^ - http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net – Spawn Sep 21 '15 at 03:49
  • Yep. I have for four hors. All of them says the same things. Didn't work for me. – Json T Sep 21 '15 at 03:49
  • I tried this `String strHostName = HttpContext.Current.Request.UserHostAddress.ToString(); IPAddress =System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();` but it gets the network's ip – Json T Sep 21 '15 at 03:59

0 Answers0