A Query In A Program Language Can Be Used To Redirect Web Visitors By Country Using .NET Framework in C# or VB.NET

You are searching about A Query In A Program Language Can Be Used To, today we will share with you article about A Query In A Program Language Can Be Used To was compiled and edited by our team from many sources on the internet. Hope this article on the topic A Query In A Program Language Can Be Used To is useful to you.

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

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

This article shows you how this can be done using a .NET component.

Let’s take a simple example. Company XYZ is a multinational company with major customers from the United States and Japan. The company’s official website is available in both English and Japanese. The default page is in English and the visitor can switch to Japanese by changing the default language option. A potential problem exists when a Japanese visitor does not understand English and cannot navigate the website. So, let’s come up with a simple solution to help XYZ company redirect all their internet traffic from Japan country to Japanese language site. At the same time, it drives the rest of the traffic to the English site.

In this example, we use the fully functional IP2Location(TM) .NET component available at http://www.ip2location.net/download/IP2LocationDotNetComponent.ZIP to query the visitor’s IP address and country. First, install the IP2Location(TM) .NET component. The IP2Location(TM) .NET component will be installed on your local drive. Next, get the IP2Location.DLL .NET component and the sample database from the directory ie. c:Program FilesIP2Location by default. You must add a reference to this component from your Visual Studio web project. A copy of this component will be copied to the /bin folder under the project. One in ten requests for an unregistered component has a random 5 second delay.

Let’s assume the English web page as index_en.htm and the Japanese web page as index_jp.htm. We use a simple default.asp script to detect the visitor’s country of origin. If the visitor is from Japan, redirect them to index_jp.htm, otherwise index_en.htm. Simple? Here is the code and comments to serve as an explanation for default.asp.

Sample Codes in a VB.NET Webform

—————————————

Imports IP2Location

Private SubQuery ( ByVal strIPAddress As String )

Dimension OIPResult As New IP2Location.IPResult

try it

If strIPAddress “” Then

IP2Location.Component.IPDatabasePath = “C:Program FilesIP2LocationDatabaseIP-COUNTRY.SAMPLE.BIN”

oIPResult = IP2Location.Component.IPQuery(strIPAddress)

Select Case oIPResult.Status

Case “OK”

If oIPresult.CountryShort = “JP” Then

‘ The visitor is from Japan

‘ Redirect URL to index_jp.htm

Response.Redirect(“index_jp.htm”)

Other

The visitor is not from Japan

‘ Redirect URL to index_en.htm

Response.Redirect(“index_en.htm”)

If it ends

Case “EMPTY_IP_ADDRESS”

Response.Write(“The IP address cannot be empty.”)

case “INVALID_IP_ADDRESS”.

Response.Write(“Invalid IP address.”)

Case “MISSING_FILE”.

Response.Write(“Invalid database path.”)

Finish the selection

Other

Response.Write(“The IP address cannot be empty.”)

If it ends

Catch the past as an exception

Write Reply (eg Message)

Finally

oIPResult = Nothing

End the test

Last Sub

Sample Codes in C# Webform

———————————-

Using IP2Location;

private void request(string strIPAddress)

{

IPResult oIPResult = new IP2Location.IPResult();

try it

if (strIPAddress != “”)

IP2Location.Component.IPDatabasePath = “C:Program FilesIP2LocationDatabaseIP-COUNTRY.SAMPLE.BIN”;

oIPResult = IP2Location.Component.IPQuery(strIPAddress);

switch(oIPResult.Status.ToString())

“OK” status:

if (oIPResult.CountryShort == “JP”)

Response.Redirect(“index_jp.htm”)

else

Response.Redirect(“index_en.htm”)

pause;

Case “EMPTY_IP_ADDRESS”:

Response.Write(“IP address cannot be empty.”);

pause;

Case “INVALID_IP_ADDRESS”:

Response.Write(“Invalid IP address.”);

pause;

Case “MISSING_FILE”:

Response.Write(“Invalid database path.”);

pause;

else

Response.Write(“IP address cannot be empty.”);

catch (except exception)

Response.Write(ex.Message);

finally

oIPResult = null;


}

Compile this project and upload it to the website. All visitors will pass this check before being redirected to the respective web page.

Video about A Query In A Program Language Can Be Used To

You can see more content about A Query In A Program Language Can Be Used To on our youtube channel: Click Here

Question about A Query In A Program Language Can Be Used To

If you have any questions about A Query In A Program Language Can Be Used To, please let us know, all your questions or suggestions will help us improve in the following articles!

The article A Query In A Program Language Can Be Used To was compiled by me and my team from many sources. If you find the article A Query In A Program Language Can Be Used To helpful to you, please support the team Like or Share!

Rate Articles A Query In A Program Language Can Be Used To

Rate: 4-5 stars
Ratings: 7383
Views: 98287338

Search keywords A Query In A Program Language Can Be Used To

A Query In A Program Language Can Be Used To
way A Query In A Program Language Can Be Used To
tutorial A Query In A Program Language Can Be Used To
A Query In A Program Language Can Be Used To free
#Redirect #Web #Visitors #Country #NET #Framework #VBNET

Source: https://ezinearticles.com/?Redirect-Web-Visitors-By-Country-Using-.NET-Framework-in-C-or-VB.NET&id=215385

Related Posts

default-image-feature

A Proposed Law Drafted In Legal Language Is Called A The CYFS Succubus – And How to Fight It

You are searching about A Proposed Law Drafted In Legal Language Is Called A, today we will share with you article about A Proposed Law Drafted In…

default-image-feature

A Programmer Uses In Selecting The Language For A Project Nearshore Net Developers – Important Things to Bear in Mind

You are searching about A Programmer Uses In Selecting The Language For A Project, today we will share with you article about A Programmer Uses In Selecting…

default-image-feature

A Popular Bible Verse In Different Languages Around The World Chapter 2: The Apostolic Canopy – An Acts 1:8 Strategy

You are searching about A Popular Bible Verse In Different Languages Around The World, today we will share with you article about A Popular Bible Verse In…

default-image-feature

A Plain Language Definition That Uses No Complicated Mathematical Terms Influencing The Quality Of Education

You are searching about A Plain Language Definition That Uses No Complicated Mathematical Terms, today we will share with you article about A Plain Language Definition That…

default-image-feature

A Person Who Uses Proactive Language Is Always Looking At: Facebook and Procrastination: Your Friend or Enemy?

You are searching about A Person Who Uses Proactive Language Is Always Looking At:, today we will share with you article about A Person Who Uses Proactive…

default-image-feature

A Person Who Speaks Three Or More Languages Is Called The 3 Main Principles of Object Oriented Programming – How to Program With Java

You are searching about A Person Who Speaks Three Or More Languages Is Called, today we will share with you article about A Person Who Speaks Three…