jbajaj
asked on
redirecting user to the correc domain based on the country of access
I have two portal omvedstore.com and omvedstore.in hosted seperately on two shared servers.
Case 1: Now if a user from India tries to access omvedstore.com he is redirected to omvedstore.com.
Case 2: If a user tries to access omvedstore.in form overseas ( any county but india) he gets redircted to omvedstore.com
In order to do so I have put the code snipsets on both the server, which works well for case 1. However it fails for case 2
Below is the code
Code in Omvedstore.com ( checks is the user is from india . If yes sends him to omvedstore.in else to omvedstore.com ). This works well
string ipAddress = Request.ServerVariables["R EMOTE_ADDR "];
ip_to_country data = stmngr.GetIPtoCountry(ipAd dress);
if (data != null)
{
if (data.TwoCountryCode.ToLow er().Trim( ) == ("IN").ToLower().Trim())
{
if (ConfigurationManager.AppS ettings["I ndiaSiteUr l"] != null &&
!String.IsNullOrEmpty(Conf igurationM anager.App Settings[" IndiaSiteU rl"].ToStr ing()))
Response.Redirect(String.F ormat("{0} ", ConfigurationManager.AppSe ttings["In diaSiteUrl "].ToStrin g()));
}
else
{
Response.Redirect(String.F ormat("{0} ", ConfigurationManager.AppSe ttings["In diaSiteUrl "].ToStrin g()));
}
}
Code in omvedstore.in ( checks if user is from overseas and redirects him to omvedstore.com . This doesnt work. The user stays on omvedstore.in )
string ipAddress = Request.ServerVariables["R EMOTE_ADDR "];
ip_to_country data = stmngr.GetIPtoCountry(ipAd dress);
if (data != null)
{
if (data.TwoCountryCode != "IN")
{
if (ConfigurationManager.AppS ettings["G lobalSiteU rl"] != null &&
!String.IsNullOrEmpty(Conf igurationM anager.App Settings[" GlobalSite Url"].ToSt ring()))
Response.Redirect(String.F ormat("{0} ?cntCode=U S", ConfigurationManager.AppSe ttings["Gl obalSiteUr l"].ToStri ng()));
}
}
Please let me know what the issue might be.
Else you can suggest me a better code as well
Thanks
Case 1: Now if a user from India tries to access omvedstore.com he is redirected to omvedstore.com.
Case 2: If a user tries to access omvedstore.in form overseas ( any county but india) he gets redircted to omvedstore.com
In order to do so I have put the code snipsets on both the server, which works well for case 1. However it fails for case 2
Below is the code
Code in Omvedstore.com ( checks is the user is from india . If yes sends him to omvedstore.in else to omvedstore.com ). This works well
string ipAddress = Request.ServerVariables["R
ip_to_country data = stmngr.GetIPtoCountry(ipAd
if (data != null)
{
if (data.TwoCountryCode.ToLow
{
if (ConfigurationManager.AppS
!String.IsNullOrEmpty(Conf
Response.Redirect(String.F
}
else
{
Response.Redirect(String.F
}
}
Code in omvedstore.in ( checks if user is from overseas and redirects him to omvedstore.com . This doesnt work. The user stays on omvedstore.in )
string ipAddress = Request.ServerVariables["R
ip_to_country data = stmngr.GetIPtoCountry(ipAd
if (data != null)
{
if (data.TwoCountryCode != "IN")
{
if (ConfigurationManager.AppS
!String.IsNullOrEmpty(Conf
Response.Redirect(String.F
}
}
Please let me know what the issue might be.
Else you can suggest me a better code as well
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are doing the redirect in .net so you need soem .net experts to look at this.
I have requested attention ofr you and a mod shoudl add this to the .net groups.