SIGN UP MEMBER LOGIN:    
ARTICLE

Track Client Location From IP Address in ASP.NET

Posted by Krishna Garad Articles | ASP.NET Programming August 27, 2011
In this article we will discuss second method to find client location on the basis of Ip Address of the client.
Reader Level:

Introduction

In last article Find Client IP And Location we seen how to find client IP address and location using http://freegeoip.appspot.com/  which is not free webservice to get the client location information.
 
In this article we will discuss second method to find client location on the basis of Ip Address of the client.

BackGround:

In so many cases web developer's need to track client location information eg. You are developing the commercial website and you need to show the user what kind of offer's are available but you don't know which area he belongs to. In such cases instead to asking user which area you belongs and then show the offer's in that area we can track his location and without asking his location information can show the details.

In last article I've used the freegeoip.appspot.com by passing the IP address of client and then get the location here also same thing we will do but with different service provider i.e. http://api.ipinfodb.com . For accessing the service from ipinfodb you need to register first they will provide you a API key which we will use in our application to make request for location details. So just register HERE. And get the API key.

GetLocation:

The GetLocation method will accept IP address to track location and retuns a DataTable which contains location details of the IP address.

private DataTable GetLocation(string ipaddress)
    {
        string url = "http://api.ipinfodb.com/v2/ip_query.php?key={0}&ip={1}&timezone=true";

        url = String.Format(url, "<your API key Here", ipaddress);

        HttpWebRequest httpWRequest = (HttpWebRequest)WebRequest.Create(url);
        using (HttpWebResponse httpWResponse = (HttpWebResponse)httpWRequest.GetResponse())
        {

            XmlTextReader xtr = new XmlTextReader(httpWResponse.GetResponseStream());
            DataSet ds = new DataSet();
            ds.ReadXml(xtr);
            return ds.Tables[0];
        }

    }

In above GetLocation method instead of <your API key> write the API key provided by apinfodb.com after registration and then call the method which will return the location details of user.

Conclusion:

By using this simple API we can track our client very easily.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Gauge for SharePoint
Become a Sponsor