5

I'm using Sitecore 8.0 with GeoIP service. I'd like to redirect user to a specific sitecore item depending on his location. I didn't see any redirect rule in personalization rules. Any help in this regard is highly appreciated.

1 Answer 1

2

You can find location based on visitor IP and can implement redirect condition for a particular url. e.g:

System.Net.IPAddress ipAddress = null;
string country = string.Empty;

if (System.Net.IPAddress.TryParse(Request.ServerVariables["REMOTE_ADDR"], out ipAddress))
{
    Sitecore.Analytics.Lookups.GeoIpOptions geoIpOptions = new Sitecore.Analytics.Lookups.GeoIpOptions();
    geoIpOptions.Ip = ipAddress;
    Sitecore.Analytics.Lookups.GeoIpResult geoIpResult1 = Sitecore.Analytics.Lookups.GeoIpManager.GetGeoIpData(geoIpOptions);
    Thread.Sleep(5000);
    Sitecore.Analytics.Lookups.GeoIpResult geoIpResult = Sitecore.Analytics.Lookups.GeoIpManager.GetGeoIpData(geoIpOptions);

    if (geoIpResult != null)
    {
        country = geoIpResult.GeoIpData.Country;
    }

    if (country == "HK")
    {
        string link = "";
        Item redirectItem = Sitecore.Context.Database.GetItem(link);      
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.