rubbershells.com rubbershells.com rubbershells.com
  Main -> About Us -> Add Your Link -> Privacy of Info -> ToS -> Submit Article
Search:   
Add Url
 

Recreation & Entertainment

Tour & Travel

Drink & Food

Business & Commerce

Children

Self Management

Garden & Home

Games & Play

Computers & Software

Culture & Art

Society & Issues

Science & Research

Policies & Law

News & Media

Healthcare & Treatment

Shopping Online

Finance & Banking

Sports & Adventure

Health & Therapy

Relationship & Lifestyle

Education & Reference

Automotive

Property & Agents

Careers & Employment


 

Main » Computers & Software » Web Design & Development
 

Redirect Web Visitors By Country Using .NET Framework in C# or VB.NET

 
Author: Ivy Tang

There are times when it is useful to redirect a visitor to different default web page based on the visitor's country of origin. One practical usage is to redirect visitor to web page with the language recognized by the visitor.

This article shows you how by using .NET component, it can be done.

Let us take a simple case study. Company XYZ is multi-national company with major customers from United States and Japan. The company official website is developed in both English and Japanese languages. The default page is in English language and visitor can switch to Japanese by changing the default language option. There exists a potential problem when a Japanese visitor does not understand English and it could not navigate the web site. So let us develop a simple solution to help Company XYZ redirecting all Internet traffic from country Japan to the Japanese language site. Meanwhile it drives the rest traffic to English site.

In this example, we use a fully functional IP2Location .NET component available at http://www.ip2location.net/download/IP2LocationDotNetComponent.ZIP to query country 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 component and sample database from the directory, ie. c:Program FilesIP2Location by default. You need to add a reference to this component from your Visual Studio web project. A copy of this component will be copied into /bin directory under the project. For unregistered component, there is a random 5-second delay in one out of ten queries.

Let's assume the English web page as index_en.htm and Japanese web page as index_jp.htm. We implement a simple script default.asp to detect visitor's country of origin. If the visitor is from Japan, then redirect him/her to index_jp.htm, otherwise index_en.htm. Simple? Here is the code and the comments serve as explanation default.asp.

Sample Codes in VB.NET Webform ------------------------------

Imports IP2Location Private Sub Query(ByVal strIPAddress As String)

Dim oIPResult As New IP2Location.IPResult

Try

If strIPAddress <> "" Then

IP2Location.Component.IPDatabasePath = "C:\Program Files\IP2Location\Database\IP-COUNTRY.SAMPLE.BIN"

oIPResult = IP2Location.Component.IPQuery(strIPAddress)

Select Case oIPResult.Status

Case "OK"

If oIPResult.CountryShort = "JP" Then

' Visitor is from Japan

' Redirect the URL to index_jp.htm

Response.Redirect("index_jp.htm")

Else

' Visitor is not from Japan

' Redirect the URL to index_en.htm

Response.Redirect("index_en.htm")

End If

Case "EMPTY_IP_ADDRESS"

Response.Write("IP Address cannot be blank.")

Case "INVALID_IP_ADDRESS"

Response.Write("Invalid IP Address.")

Case "MISSING_FILE"

Response.Write("Invalid Database Path.")

End Select

Else

Response.Write("IP Address cannot be blank.")

End If

Catch ex As Exception

Response.Write(ex.Message)

Finally

oIPResult = Nothing

End Try End Sub

Sample Codes in C# Webform -------------------------- Using IP2Location; private void Query(string strIPAddress) {

IPResult oIPResult = new IP2Location.IPResult();

try

{

if (strIPAddress != "")

{

IP2Location.Component.IPDatabasePath = "C:\Program Files\IP2Location\Database\IP-COUNTRY.SAMPLE.BIN"; oIPResult = IP2Location.Component.IPQuery(strIPAddress);

switch(oIPResult.Status.ToString())

{

case "OK":

if (oIPResult.CountryShort == "JP") {

Response.Redirect("index_jp.htm")

} else {

Response.Redirect("index_en.htm")

}

break;

case "EMPTY_IP_ADDRESS":

Response.Write("IP Address cannot be blank.");

break;

case "INVALID_IP_ADDRESS":

Response.Write("Invalid IP Address.");

break;

case "MISSING_FILE":

Response.Write("Invalid Database Path.");

break;

}

}

else

{

Response.Write("IP Address cannot be blank.");

}

}

catch(Exception ex)

{

Response.Write(ex.Message);

}

finally

{

oIPResult = null;

} }

Compile and upload this project to the web site. All visitors will go through this screening before redirect to an appropriate web page.

Author Bio:
Ivy Tang is a renowned writer. Ivy likes to compose articles about this field.
You can search for this article using: web site development, web design & development, website development tampa
 
 
 

Related Articles

 
Demand Unlimited Auto-Responders with Your Hosting Accounting
 
5 Good Reasons For Using Yahoogroups To Start Your Own Ezine
 
Port Scanning; the Good, Bad, & Ugly
 
Samsung D800 - Impressive in Looks, Versatile in Functions
 
The KG800 Chocolate GSM by LG Phone
 
Guide To Safe Online Shopping
 
Power Up! UPSs and Surge Protectors
 
Highly Targeted Web Traffic - One Key To Making Online Sales!
 
Use Email Marketing Wisely; Stand Out From Junk Mail
 
Custom Web Site Design Companies
 
 
 
Main -> Privacy of Info -> ToS
© 2008 www.rubbershells.com All Rights Reserved.