The most reliable method is to look up the visitor's IP address and determine the country from that but that requires a large IP address database or call to another web site and there is usually a cost associated with these methods (31-Jan-08 update: see http://www.ourline.com/asp/findip.asp for a free script and database).
A simpler (and free) method is to try and determine the location based on the visitor's language settings.
The server variable 'HTTP_ACCEPT_LANGUAGE' will return a 2 or 5 character string with the visitor's language setting (assuming they have selected it correctly). You can then use this string to lookup what country(s) that language setting is associated with.
Whilst hardly a perfect solution, this method works quite reliably for determining major countries.
Here is a sample script that attempts to return a 2-digit country code based on this variable.
A better implementation of this method would be to have a lookup database which lists each of the possible language settings and looks up the most likely country.
The complete list of possible languages:
Chinese/Hong Kong (zh-hk)
English/United Kingdom (en-gb)
English/United Satates (en-us)
English/New Zealand (en-nz)
English/South Africa (en-za)
Indonesian (id or in)
Italian/ Switzerland (it-ch)
Russian /Moldavia (ru-mo)
Scots Gaelic (gd)
Spanish (es or es-do)
Spanish/Costa Rica (es-cr)
Spanish/El salvador (es-sv)
Spanish/Puerto Rico (es-pr)
by John Avis | May 6, 2020
If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.
by John Avis | November 4, 2019
As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.
by John Avis | October 15, 2019
For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.