How can I get the IP address of a visitor to my site?
The documentation I can find on RemoteAddress is pretty confusing.
I found one item on the web showing :
string ip=Request.ServerVariables("REMOTE_ADDR");
But I get errors with that. So I'm at a loss here.
TIA
Ken
Loading
Roei BarPosted Sep 10, 2009, 2:06 PM
Ken KraskaPosted May 17, 2022, 2:59 PM
Hi - The question asks "Getting the remote IP address of a visitor to my site" which is what I would like to do. However, the final working response shows -
String hostName = System.Net.Dns.GetHostName();
lblIpAdr.Text = hostName ;
which works for getting "hostname" , how do I get the "IP" address?
I am using MVC Core 5.0. when I try other solutions I can't seem to get them to work.
Thanks
Ken BarrettPosted Sep 10, 2009, 2:01 PM
String hostName = System.Net.Dns.GetHostName();
lblIpAdr.Text = hostName ;