1

We are using Sitecore 7.2 in our project. We have a requirement that based on country Geo-IP home page needs to be redirected. Please help me in achieving this functionality in local instance.

4

We are usually faking local IP address in this case.

We use querystring such as "?ipaddress={Fake_Ip_goes_here}" to inject faked ip address.

In your code, in place where you determine IP address, just add another condition if this query string is present, use value provided instead.

There are sites like this one https://www.nirsoft.net/countryip/ which will help you get proper IP for particular country to test whether redirection is working as expected.

Of course on production environment this is not desired so we usually introduce some kind of setting "EnableSettingIpAddressFromQueryString" which is on production set to False and we add another condition to upper one whether this setting is true so we only enable setting IP address from query string on non-production servers.

  • 3
    I can't remember in which version it was added but I usually use setting "Analytics.ForwardedRequestHttpHeader". – josedbaez Jan 22 at 12:22
2

You can add a processor to change request IP address locally in the analytics "createVisit" pipeline.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <createVisit>
        <processor type="Sitecore.Foundation.Geolocation.Pipelines.Testing.ChangeIP, Sitecore.Foundation.Geolocation"
                   patch:after="processor[@type='Sitecore.Analytics.Pipelines.CreateVisits.XForwardedFor, Sitecore.Analytics']">
        </processor>
      </createVisit>
    </pipelines>
    <settings>
      <setting name="Foundation.Geolocation.Testing.IP" value="77.73.57.78"/>
    </settings>
  </sitecore>
</configuration>

namespace Sitecore.Foundation.Geolocation.Pipelines.Testing
{
  public class ChangeIP : CreateVisitProcessor
  {
    public override void Process(CreateVisitArgs args)
    {
        Assert.ArgumentNotNull((object)args, "args");

        string ip = new IPAddress(Tracker.Current.Interaction.Ip).ToString();
        if (ip != "0.0.0.0" && ip != "127.0.0.1")
        {
            return;
        }

        IPAddress address;
        if (IPAddress.TryParse(Configuration.Settings.GetSetting("Foundation.Geolocation.Testing.IP"), out address))
        {
            args.Interaction.Ip = address.GetAddressBytes();
        }
    }
  }
}
0

One way I've done this before is to use ngrok http tunneling https://ngrok.com, and then use a VPN service to imitate the connection. This way works for all web applications, not just sitecore. I think this is a great way for non technical people (eg stakeholders) to test the functionality without mucking around with anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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