troubleshooting Question

redirecting user to the correc domain based on the country of access

Avatar of jbajaj
jbajaj asked on
Web DevelopmentMicrosoft IIS Web Server.NET Programming
2 Comments1 Solution303 ViewsLast Modified:
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["REMOTE_ADDR"];

                    ip_to_country data = stmngr.GetIPtoCountry(ipAddress);
                    if (data != null)
                    {
                        if (data.TwoCountryCode.ToLower().Trim() == ("IN").ToLower().Trim())
                        {
                            if (ConfigurationManager.AppSettings["IndiaSiteUrl"] != null &&
                            !String.IsNullOrEmpty(ConfigurationManager.AppSettings["IndiaSiteUrl"].ToString()))
                                Response.Redirect(String.Format("{0}", ConfigurationManager.AppSettings["IndiaSiteUrl"].ToString()));
                        }
                        else
                        {
                            Response.Redirect(String.Format("{0}", ConfigurationManager.AppSettings["IndiaSiteUrl"].ToString()));
                        }
                    }


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["REMOTE_ADDR"];
                    ip_to_country data = stmngr.GetIPtoCountry(ipAddress);
                    if (data != null)
                    {
                        if (data.TwoCountryCode != "IN")
                        {
                            if (ConfigurationManager.AppSettings["GlobalSiteUrl"] != null &&
                            !String.IsNullOrEmpty(ConfigurationManager.AppSettings["GlobalSiteUrl"].ToString()))
                                Response.Redirect(String.Format("{0}?cntCode=US", ConfigurationManager.AppSettings["GlobalSiteUrl"].ToString()));
                        }
                    }


Please let me know what the issue might be.

Else you can suggest me a better code as well

Thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros