Search code examples
asp.net-mvcgeolocationip

How to get the geographic location using IP Address in asp.net mvc


I know that this code:

string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (string.IsNullOrEmpty(ipAddress))
        {
            ipAddress = Request.ServerVariables["REMOTE_ADDR"];
        }

will give me the IP Address of the user but I don't know how to get the location of the user

I want to know the location and related information on basis of IP Address.


Solution

  • This should help you - http://freegeoip.net/

    freegeoip.net is a public REST API for searching geolocation of IP addresses and host names. Send HTTP GET requests to: freegeoip.net/{format}/{ip_or_hostname}. The API supports both HTTP and HTTPS and Supported formats are csv, xml or json.