I posted the following Macro code in the T-Shirt contest, and it should provide you the basics for getting the Visitor's Country so that you can redirect them. This uses the MaxMind GeoIP Databse that ships with Kentico and is part of WebAnalytics and hence you may need a license that supports that.
[MacroMethod(typeof (bool), "Checks if the current visitors IP Address is in blocked countries", 1)]
public static object IsVisitorInBlockedCountry(EvaluationContext context, params object[] parameters)
{
if (parameters.Length != 0)
throw new NotSupportedException();
string userIP = RequestContext.UserHostAddress;
int countryId = GeoIPHelper.GetCountryIDByIp(userIP);
if (countryId == 0)
{
// check if it's the localhost so that it skips logging
if (userIP != "::1")
{
string countryCode = "";
// we couldn't resolve the country, so let's add a log entry
var location = GeoIPHelper.GetLocationByIp(userIP);
if (location != null)
countryCode = location.CountryCode;
string evDescription = "Unable to determine country for visitor." +
"" +
$"IP Address: {userIP}" +
$"Country Code: {countryCode}";
// we do have a countryName so let's log this.
EventLogProvider.LogEvent(EventType.WARNING, "Blocked Country", $"LOOKUP - {countryCode}", evDescription);
}
// note: hard-coded default value (should use the settings app instead)
return false;
// return CustomEcommerceSettings.UnknownCountryIsBlocked(new SiteInfoIdentifier(SiteContext.CurrentSiteID));
}
// We use a custom class to store the blocked countries
return BlockedCountryInfoProvider.IsCountryBlocked(countryId, SiteContext.CurrentSiteID);
}