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
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);
}