Q: I have fetch the ip address of my website visitor, how can i get their geographic location too? I want to get the geographic location of my website visitors and store it in my database, have fetch the ip address already.
I'm using asp.net 3.0
protected void Page_Load( object sender, EventArgs e)
    {
        // Track Visitors
        string ipAddress = IpAddress();
        string hostName = Dns .GetHostByAddres(ipAddress).HostName;
        StreamWriter wrtr = new StreamWriter (Server.MapPath( "visitors.log" ), true );
        wrtr.WriteLine( DateTime .Now.ToString() + " | " + ipAddress + " | " + hostName + " | " + Request.Url.ToString());
        wrtr.Close();
    }

    private string IpAddress()
    {
        string strIpAddress;
        strIpAddress = Request.ServerVariables[ "HTTP_X_FORWARDED_FOR" ];
        if (strIpAddress == null )
            strIpAddress = Request.ServerVariables[ "REMOTE_ADDR" ];
        return strIpAddress;
    }


A: There is no inbuilt method to that. There are web-services on the internet that will provide such mapping. Such databases "GeoIP databases" are also available for local use.
But it would be best to subscribe to an updated web-service and use that to get the location.
Google's Client Location API's should help you here.
Some modern browsers will send you the users location. You can use that. But since this is not followed by all browsers, it is not reliable. You can check out the Geo Location API provided by w3.org.
