Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1071707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:45:00+00:00 2026-05-16T20:45:00+00:00

My code: protected void Page_Load(object sender, EventArgs e) { String userHost = Request.UserHostName }

  • 0

My code:

    protected void Page_Load(object sender, EventArgs e)
    {
        String userHost = Request.UserHostName
    }

This is fetching the IP address alright, but now I want to know the country of the visitor and USE that country name to redirect the visitor to some webpage accordingly.

I came across this library but have no clue how to use it in the project. Actually I do, but I am not sure so I am asking.

http://ipaddressextensions.codeplex.com/

When I download from the above the ZIP folder has a DLL file and an XML file. Now, what do I do with these two? Like include in the project. Then what do I type in the code file?

Something like the following.

if (countryName=="France")
{
    response.redirect("www.mysite.fr")
}
else
    if(countryName=="India")
    {
        response.redirect("www.mysite.in")
    }

and so on…

How do I go about it? Also do I really need to type SO many if blocks for ALL the countries. How do I shorten this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:45:00+00:00Added an answer on May 16, 2026 at 8:45 pm

    To shorten your code put all the countries in a dictionary.

    Dictionary<string,string>  dict;
    
    public void Init(){
        dict = new Dictionary<string,string>();
        dict["India"] = "www.mysite.in";
        dict["France"] = "www.mysite.fr";
    }
    
    public string GetPage(string country){
        string result = dict["Default"];
    
        if(dict.ContainsKey(theKey)){
            result  = dict[theKey];
        }
        return result;
    }
    

    Just add the reference and then the “using statement” and the API is yours to use.

    You could even alter the above to take in an IP address.

    First add the reference and the below using to your code.

    using WorldDomination.Net;
    
    public string GetPage(string ipAddress){
        string result = null;
        IPAddress ipAddress;
        if (IPAddress.TryParse(userHostIpAddress, out ipAddress))
        {
            string fullNameKey= ipAddress.Country();
            //Or you could use two letter code
            //string twoLetterKey = ipAddress.Iso3166TwoLetterCode();
            if(dict.ContainsKey(theKey)){
                 result = dict[fullNameKey];
            }
        }
        else
        {
            result = dict["Default"];
        }
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is the simple code: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
In the following code protected void Page_Load(object sender, EventArgs e) { List<string> listSetValues =
I have this code protected void Page_Load(object sender, EventArgs e) { TblPrikaz.BorderWidth = 1;
I have the following code: protected void Page_Load(object sender, EventArgs e) { var openId
Im setting the the datasource with the following code: protected void Page_Load(object sender, EventArgs
I have made something like the following code: protected void Page_Load(object sender, EventArgs e)
I am trying to fetch the IP address using this:- protected void Page_Load(object sender,
~/Admin/AdimHome.aspx.cs C# code protected void Page_Load(object sender, EventArgs e) { System.Text.StringBuilder sb = new
I have AutoEventWireup=true and in my code behind protected void Page_Init(object sender, EventArgs e)
Here is my code: public partial class Image : System.Web.UI.Page { protected void Page_Load(object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.