2

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.

1

4 Answers 4

5

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.

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

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.

0

One of the easiest way to fake the local IP is by using the chrome plugin "Sitecore Analytics Testing Tools".

https://chrome.google.com/webstore/detail/sitecore-analytics-testin/pecalkbdlhhhcoenmcjnmhgnncnkdgak

Here you can add different profiles and use accordingly.

enter image description here

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.