Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 14, 2008 10:22 AM by BennySutton
Mar 07, 2007 08:11 AM|LINK
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,
Ordina - SI&D - DCM
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")
Mar 08, 2007 07:40 AM|LINK
Mar 08, 2007 08:20 AM|LINK
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.
Jun 14, 2008 10:22 AM|LINK
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!
here's how to do it...
You need to make a countries table for your lookups