Detect Country C#

A

Antoni Massó Mola

Hi,

I need to detect from which Country (City would be great) the user is
connecting.

Is there any free script for doing this in C#?

Thanks
 
J

John Saunders

Antoni Massó Mola said:
Hi,

I need to detect from which Country (City would be great) the user is
connecting.

Is there any free script for doing this in C#?

In general, this cannot be done. Although IP address ranges are allocated by
companies, and although a company may have an address, there is nothing
which demands that a given IP address may only be used within the country in
which the registering company is located.

You'd probably be better off asking the user where he or she is located, and
then hope that the user isn't moving between countries.
 
A

Antoni Massó Mola

There are a number of website who have this service and decect the country
of my IP.

There must be a way to achieve this. I'll search to see if there is a
commercial version.
 
S

Steve Drake

this.Page.Request.UserLanguages.GetValue(0).ToString() will give you a
language setting, eg en-gb for UK and en-us for the USA, plus many many
more, have a look at TOOLS - OPTIONS - LANGUAGES (button) - ADD (button).

but... this tells you what language the user wants the website to be in, but
in most cases this could be the country, if its for a form you could default
the language based on this value. This is what GOOGLE ect use to redirect
the countries version of the website.

Steve
 
J

John Saunders

Antoni Massó Mola said:
There are a number of website who have this service and decect the country
of my IP.

There must be a way to achieve this. I'll search to see if there is a
commercial version.

There are a number of commercial versions which are unable to tell you the
actual country the user is in. This is because IP addresses cannot reliably
be used to tell you the country.

There is nothing in the standards or RFCs which says that there must be a
correspondence between ranges of IP addresses and countries. Any of these
services are simply using a fluke of the registration process - that when
someone registers for a range of IP addresses, an address is recorded, and
that the address contains a country. But this has absolutely nothing to do
with how those IP addresses are distributed, or to which country.

Sorry, but if you need something reliable (perhaps for legal reasons), then
this isn't it.
 
A

Antoni Massó Mola

Thanks Steve!

Steve Drake said:
this.Page.Request.UserLanguages.GetValue(0).ToString() will give you a
language setting, eg en-gb for UK and en-us for the USA, plus many many
more, have a look at TOOLS - OPTIONS - LANGUAGES (button) - ADD (button).

but... this tells you what language the user wants the website to be in, but
in most cases this could be the country, if its for a form you could default
the language based on this value. This is what GOOGLE ect use to redirect
the countries version of the website.

Steve
 
J

John Saunders

Antoni Massó Mola said:
Yes, you are correct.

I've only found databases with tons of IP's.

And if these IPs can reliably tell you the country corresponding to the IP
address, then I'll be very surprised.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top