Right now I am buildling a hitcounter for my webpage. From every user that visits my page I save data like browsername, browserversion, IP address, etc.
I also like to get the country wherefrom the user browses to my website and the language he/she uses on his/her system. I searched in the Request object
but I couldn't find anything. Is it possible to get the user's country & language and how?
You can get a rough idea of the country that the IP address belongs to by doing a reverse lookup on the IP address. There are some companies that provide databases containing IP to country mapping tables. There might even be some free web services out
there. Google for "IP Locator".
You can get the language for the Browser from Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
Hi I am wondering the difference between HttpRequest.UserLanguages and Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")?
Looking at the
docs, it appears that HttpRequest.UserLanguages returns a sorted array of language preferences, whereas the Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") returns a (comma-separated)
string. In other words, HttpRequest.UserLanguages appears to take the value of Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") and does a little bit of preparatory work on them, if you prefer to work with arrays.
For instance, I wanted to do everything I could to help users fill in forms i.e. place orders! So I decided to work out how to set the 'select country' dropdown to the user's current location. The only foolproof way is to do a reverse lookup on their IP
address, but that requires a third party. I decided to use the built-in asp.net classes (CultureInfo etc.) - it's free!
Johan Machie...
Member
18 Points
7 Posts
Get Client's country & language
Mar 07, 2007 08:11 AM|LINK
Dear reader,
Right now I am buildling a hitcounter for my webpage. From every user that visits my page I save data like browsername, browserversion, IP address, etc.
I also like to get the country wherefrom the user browses to my website and the language he/she uses on his/her system. I searched in the Request object
but I couldn't find anything. Is it possible to get the user's country & language and how?
Thank you in advance,
Johan Machielse
Ordina - SI&D - DCM
Mikesdotnett...
All-Star
155597 Points
19981 Posts
Moderator
MVP
Re: Get Client's country & language
Mar 07, 2007 09:26 AM|LINK
You can get a rough idea of the country that the IP address belongs to by doing a reverse lookup on the IP address. There are some companies that provide databases containing IP to country mapping tables. There might even be some free web services out there. Google for "IP Locator".
You can get the language for the Browser from Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
Web Pages CMS | My Site | Twitter
himawari
Member
328 Points
63 Posts
Re: Get Client's country & language
Mar 08, 2007 07:40 AM|LINK
Mikesdotnett...
All-Star
155597 Points
19981 Posts
Moderator
MVP
Re: Get Client's country & language
Mar 08, 2007 08:20 AM|LINK
Looking at the docs, it appears that HttpRequest.UserLanguages returns a sorted array of language preferences, whereas the Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") returns a (comma-separated) string. In other words, HttpRequest.UserLanguages appears to take the value of Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") and does a little bit of preparatory work on them, if you prefer to work with arrays.
Web Pages CMS | My Site | Twitter
BennySutton
None
0 Points
6 Posts
Re: Get Client's country & language
Jun 14, 2008 10:22 AM|LINK
Request.UserLanguages(0)
but you can do a lot more when you get into itFor instance, I wanted to do everything I could to help users fill in forms i.e. place orders! So I decided to work out how to set the 'select country' dropdown to the user's current location. The only foolproof way is to do a reverse lookup on their IP address, but that requires a third party. I decided to use the built-in asp.net classes (CultureInfo etc.) - it's free!
here's how to do it...
http://www.bennysutton.com/Asp.Net/How-To/User-Country.aspx
You need to make a countries table for your lookups