views:

2128

answers:

7

I want to implement this in ASP.NET. I don't have any idea about how to do so, unfortunately.

A: 

Get the client IP and find the location of IP using any IP to geo location Mapping service.

Umesh
+2  A: 

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.

Shoban
+4  A: 

Here how it is done in asp.net

Request.ServerVariables("REMOTE_ADDR")

Get a copy of IP adress database by location here

http://www.maxmind.com/

Michael B.
+1 for Maxmind. Used it with great success.
Jakob Gade
+1  A: 

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 .

anishmarokey
That server variable is only available if your webserver is behind a proxy or some kind of network device.
David
A: 

IPAddressExtensions is a free codeplex class library if all you just want is the Country the IP is located from.

Pure.Krome
+1  A: 

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.

James
A: 

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

Zest
There's never any guarantee that the IP address has any real bearing on where the user is - for years all AOL users appeared to be in Pennsylvania, even when in the UK. With regards to ip2Location, which database file are you using? I assume one of the ones with City information?
Zhaph - Ben Duguid