0

I have a razor web application and it's published in the IIS. The problem is that I need to save the IP of the pc from the users who are login into the app. My method that returns the IP is the following:

 public static string GetLocalIPAddress()
    {
        var host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (var ip in host.AddressList)
        {
            if (ip.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString())
            {
                return ip.ToString();
            }
        }
        throw new Exception("No network adapters with an IPv4 address in the system!");
    }

But when I check my database the IP returned is the IP of the server not the IP from the actual user. Do you know how to fix it?

  • 1
    Which IP are you trying to get? The internal IP of the device on their local network? The IP of the public-facing Internet connection that might be shared with hundreds of other people? The IP address of the proxy server their data is coming through? My guess is that you can't use that value in the way you think you can. – DavidG Nov 17 '21 at 16:40
  • The internal IP of the device on the local network – Andres Espinel Nov 17 '21 at 20:29

0 Answers0