I want to implement this in ASP.NET. I don't have any idea about how to do so, unfortunately.
Get the client IP and find the location of IP using any IP to geo location Mapping service.
Why not use Google Analytics? You will get more than what you need. Alternatively you can get the client's ip and use service like ip2location to get the location.
Check this similar question as well. finding clients location in asp.net page.
Here how it is done in asp.net
Request.ServerVariables("REMOTE_ADDR")
Get a copy of IP adress database by location here
by using
string userHost = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (String.IsNullOrEmpty(userHost) ||
String.Compare(userHost, "unknown", true) == 0)
{
userHost = Request.UserHostAddress;
}
you will get users ip address . Based on this ip address you can find out visitor location details by calling some webservice .
IPAddressExtensions is a free codeplex class library if all you just want is the Country the IP is located from.
First, get the IP address of the visitor using Request.ServerVariables("REMOTE_ADDR"). Bear in mind that the visitor could be using a proxy server in which case the IP address may not be their actual IP address. For the proxy case, you can check if Request.ServerVariables("HTTP_X_FORWARDED_FOR") contains a value. This will be the actual IP address if the proxy server is not an anonymous proxy server.
Then you have 2 options, using a web service or querying data from your own database. Either way, you will need data which can match an IP address of the visitor to their country, state and city. For a web service, you can use the free FraudLabs IP2Location web service. If you prefer querying your own database, you will need to get a paid subscription to a service like IP2Location where you get to download the latest data and import into your own database.
Have tried to get exact city using IP address, but is not working properly as not giving the exact user's IP address. In some cases it may return ISP router's IP address which may point to another city.
I tried ip2location, using IP address but m not getting exact city.
Can someone help on this ?
Thanx in advance.
Regards