• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
 
Determine Web Visitors Country of Origin in the Drop Down List using .NET Framework inC# or VB.NET
 
Hexasoft Development Sdn. Bhd. (645996-K)
1-2-15 Mayang Mall Complex,Jalan Mayang Pasir 1,11950 Bandar Bayan Baru,Penang, Malaysia.URL:
{
}With the emergence of online technologies such as the Internet, people and businesses haveincreased their reliance and use of these mediums as an avenue for commerce as it can be moreconvenient. During the transaction online, there are times when it is important to preset the webvisitor's country of origin, ZIP code, ISP and domain name at the drop down list to prevent fraud andto ease the complexity of registration task. This article shows you how by using .NET Framework, itcan be done.Let us take a simple example of a user login from Canada and he needs to fill up a shopping cart. Theform may be quite complex as some businesses need more information to prevent fraud. In thiscase, there are needs to preset certain info in the drop down list such as country of origin, ZIP code,ip and domain name of where the users login. As a result, the drop down list in this example willpreset to Cananda, with the correct zip code and ip address.In this example, we use a fully functional IP2Location™ .NET component availableat
to querycountry by visitor's IP address. Firstly, install the IP2Location™ .NET component. The IP2Location™.NET component will be installed in your local drive. Next, get the IP2Location.DLL .NET componentand sample database from the directory, ie. c:\Program Files\IP2Location by default. You need to adda reference to this component from your Visual Studio web project. A copy of this component will becopied into /bin directory under the project. For unregistered component, there is a random 5-seconddelay in one out of ten queries.
Sample Codes in VB.NET Webform
------------------------------
Imports IP2LocationPrivate Sub Query(ByVal strIPAddress As String)Dim oIPResult As New IP2Location.IPResultTryIf strIPAddress <> "" ThenIP2Location.Component.IPDatabasePath = "C:\\ProgramFiles\\IP2Location\\Database\\IP-COUNTRY.SAMPLE.BIN"oIPResult = IP2Location.Component.IPQuery(strIPAddress)
 
Select Case oIPResult.StatusCase "OK"If oIPResult.CountryShort <> "-" ThenResponse.Write("<select name=country>")Response.Write("<option value="&oIPResult.CountryShort & ">" & oIPResult.CountryLong & "</option>")Response.Write("<option value=AF>AFGHANISTAN</option>")Response.Write("<option value=AL>ALBANIA</option>")Response.Write("<option value=DZ>ALGERIA</option>")Response.Write("<option value=AS>AMERICAN SAMOA</option>")Response.Write("<option value=AD>ANDORRA</option>")Response.Write("<option value=AO>ANGOLA</option>")Response.Write("<option value=AI>ANGUILLA</option>")Response.Write("<option value=AQ>ANTARCTICA</option>")Response.Write("<option value=AG>ANTIGUA AND BARBUDA</option>")Response.Write("<option value=AR>ARGENTINA</option>")Response.Write("<option value=AM>ARMENIA</option>")Response.Write("<option value=AW>ARUBA</option>")Response.Write("<option value=AP>ASIA PACIFIC</option>")Response.Write("<option value=AU>AUSTRALIA</option>")Response.Write("<option value=AT>AUSTRIA</option>")Response.Write("<option value=AZ>AZERBAIJAN</option>")Response.Write("<option value=BS>BAHAMAS</option>")Response.Write("<option value=BH>BAHRAIN</option>")Response.Write("<option value=BD>BANGLADESH</option>")Response.Write("<option value=BB>BARBADOS</option>")Response.Write("<option value=BY>BELARUS</option>")Response.Write("<option value=BE>BELGIUM</option>")Response.Write("<option value=BZ>BELIZE</option>")Response.Write("<option value=BJ>BENIN</option>")Response.Write("<option value=BM>BERMUDA</option>")Response.Write("<option value=BT>BHUTAN</option>")Response.Write("<option value=BO>BOLIVIA</option>")Response.Write("<option value=BA>BOSNIA AND HERZEGOWINA</option>")Response.Write("<option value=BW>BOTSWANA</option>")Response.Write("<option value=BV>BOUVET ISLAND</option>")Response.Write("<option value=BR>BRAZIL</option>")Response.Write("<option value=IO>BRITISH INDIAN OCEANTERRITORY</option>")Response.Write("<option value=BN>BRUNEI DARUSSALAM</option>")Response.Write("<option value=BG>BULGARIA</option>")Response.Write("<option value=BF>BURKINA FASO</option>")Response.Write("<option value=BI>BURUNDI</option>")Response.Write("<option value=KH>CAMBODIA</option>")Response.Write("<option value=CM>CAMEROON</option>")Response.Write("<option value=CA>CANADA</option>")Response.Write("<option value=CV>CAPE VERDE</option>")Response.Write("<option value=KY>CAYMAN ISLANDS</option>")Response.Write("<option value=CF>CENTRAL AFRICAN REPUBLIC</option>")Response.Write("<option value=TD>CHAD</option>")Response.Write("<option value=CL>CHILE</option>")Response.Write("<option value=CN>CHINA</option>")Response.Write("<option value=CX>CHRISTMAS ISLAND</option>")Response.Write("<option value=CC>COCOS (KEELING) ISLANDS</option>")Response.Write("<option value=CO>COLOMBIA</option>")Response.Write("<option value=KM>COMOROS</option>") 
 
Response.Write("<option value=CG>CONGO</option>")Response.Write("<option value=CD>CONGO, THE DEMOCRATIC REPUBLIC OFTHE</option>")Response.Write("<option value=CK>COOK ISLANDS</option>")Response.Write("<option value=CR>COSTA RICA</option>")Response.Write("<option value=CI>COTE D'IVOIRE</option>")Response.Write("<option value=HR>CROATIA</option>")Response.Write("<option value=CU>CUBA</option>")Response.Write("<option value=CY>CYPRUS</option>")Response.Write("<option value=CZ>CZECH REPUBLIC</option>")Response.Write("<option value=CS>CZECHOSLOVAKIA (FORMER)</option>")Response.Write("<option value=DK>DENMARK</option>")Response.Write("<option value=DJ>DJIBOUTI</option>")Response.Write("<option value=DM>DOMINICA</option>")Response.Write("<option value=DO>DOMINICAN REPUBLIC</option>")Response.Write("<option value=TP>EAST TIMOR</option>")Response.Write("<option value=EC>ECUADOR</option>")Response.Write("<option value=EG>EGYPT</option>")Response.Write("<option value=SV>EL SALVADOR</option>")Response.Write("<option value=GQ>EQUATORIAL GUINEA</option>")Response.Write("<option value=ER>ERITREA</option>")Response.Write("<option value=EE>ESTONIA</option>")Response.Write("<option value=ET>ETHIOPIA</option>")Response.Write("<option value=EU>EUROPEAN UNION</option>")Response.Write("<option value=FK>FALKLAND ISLANDS (MALVINAS)</option>")Response.Write("<option value=FO>FAROE ISLANDS</option>")Response.Write("<option value=FJ>FIJI</option>")Response.Write("<option value=FI>FINLAND</option>")Response.Write("<option value=FR>FRANCE</option>")Response.Write("<option value=FX>FRANCE, METROPOLITAN</option>")Response.Write("<option value=GF>FRENCH GUIANA</option>")Response.Write("<option value=PF>FRENCH POLYNESIA</option>")Response.Write("<option value=TF>FRENCH SOUTHERN TERRITORIES</option>")Response.Write("<option value=GA>GABON</option>")Response.Write("<option value=GM>GAMBIA</option>")Response.Write("<option value=GE>GEORGIA</option>")Response.Write("<option value=DE>GERMANY</option>")Response.Write("<option value=GH>GHANA</option>")Response.Write("<option value=GI>GIBRALTAR</option>")Response.Write("<option value=GB>GREAT BRITAIN</option>")Response.Write("<option value=GR>GREECE</option>")Response.Write("<option value=GL>GREENLAND</option>")Response.Write("<option value=GD>GRENADA</option>")Response.Write("<option value=GP>GUADELOUPE</option>")Response.Write("<option value=GU>GUAM</option>")Response.Write("<option value=GT>GUATEMALA</option>")Response.Write("<option value=GN>GUINEA</option>")Response.Write("<option value=GW>GUINEA-BISSAU</option>")Response.Write("<option value=GY>GUYANA</option>")Response.Write("<option value=HT>HAITI</option>")Response.Write("<option value=HM>HEARD ISLAND AND MCDONALDISLANDS</option>")Response.Write("<option value=VA>HOLY SEE (VATICAN CITY STATE)</option>")Response.Write("<option value=HN>HONDURAS</option>")Response.Write("<option value=HK>HONG KONG</option>")Response.Write("<option value=HU>HUNGARY</option>")Response.Write("<option value=IS>ICELAND</option>")Response.Write("<option value=IN>INDIA</option>")
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...