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?
To shorten your code put all the countries in a dictionary.
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
usingto your code.