Click here to Skip to main content
14,700,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.....
I am working on an e-commercial website. I to show some product are show in Only India and some different product show out side India.

So I want to find out visitor country for this processing.

Note :- I can't use any database.

Please help.....
Posted
Updated 11-Sep-12 3:43am
v2

   
Comments
Mohamed Mitwalli 11-Sep-12 8:29am
   
5+
Prasad_Kulkarni 11-Sep-12 8:31am
   
Thank you Mohamed!
   
write this code whereever u needed

string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(ipAddress))
            {
                ipAddress = Request.ServerVariables["REMOTE_ADDR"];
                //ipAddress = "97.96.224.60";
            }
 
            string APIKey = "ur key";
            string url = string.Format("http://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}&format=json", APIKey, ipAddress);
            using (WebClient client = new WebClient())
            {
                string json = client.DownloadString(url);
                Location location = new JavaScriptSerializer().Deserialize<location>(json);
                List<location> locations = new List<location>();
                locations.Add(location);
  s = locations[0].CountryName;
}
 

public class Location
{
    public string CountryName{ get; set; }
}

Get API key from this site
http://ipinfodb.com/ip_location_api.php[^]
in the same way we can get more details if u need it let me know
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900