How can we work with Geo-IP in local instance?












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.










share|improve this question

























  • Be aware of first request issue: kb.sitecore.net/articles/320734.

    – josedbaez
    Jan 22 at 12:23
















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.










share|improve this question

























  • Be aware of first request issue: kb.sitecore.net/articles/320734.

    – josedbaez
    Jan 22 at 12:23














1












1








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.










share|improve this question
















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.







geo-location






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 22 at 10:20









Peter Procházka

5,3401943




5,3401943










asked Jan 22 at 10:07









user4934user4934

61




61













  • Be aware of first request issue: kb.sitecore.net/articles/320734.

    – josedbaez
    Jan 22 at 12:23



















  • Be aware of first request issue: kb.sitecore.net/articles/320734.

    – josedbaez
    Jan 22 at 12:23

















Be aware of first request issue: kb.sitecore.net/articles/320734.

– josedbaez
Jan 22 at 12:23





Be aware of first request issue: kb.sitecore.net/articles/320734.

– josedbaez
Jan 22 at 12:23










3 Answers
3






active

oldest

votes


















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.






share|improve this answer





















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





share|improve this answer

































    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.






    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "664"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f16156%2fhow-can-we-work-with-geo-ip-in-local-instance%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      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.






      share|improve this answer





















      • 3





        I can't remember in which version it was added but I usually use setting "Analytics.ForwardedRequestHttpHeader".

        – josedbaez
        Jan 22 at 12:22
















      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.






      share|improve this answer





















      • 3





        I can't remember in which version it was added but I usually use setting "Analytics.ForwardedRequestHttpHeader".

        – josedbaez
        Jan 22 at 12:22














      4












      4








      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.






      share|improve this answer















      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.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 22 at 12:10

























      answered Jan 22 at 10:28









      Peter ProcházkaPeter Procházka

      5,3401943




      5,3401943








      • 3





        I can't remember in which version it was added but I usually use setting "Analytics.ForwardedRequestHttpHeader".

        – josedbaez
        Jan 22 at 12:22














      • 3





        I can't remember in which version it was added but I usually use setting "Analytics.ForwardedRequestHttpHeader".

        – josedbaez
        Jan 22 at 12:22








      3




      3





      I can't remember in which version it was added but I usually use setting "Analytics.ForwardedRequestHttpHeader".

      – josedbaez
      Jan 22 at 12:22





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





      share|improve this answer






























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





        share|improve this answer




























          2












          2








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





          share|improve this answer















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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 22 at 12:30









          Gatogordo

          12k21760




          12k21760










          answered Jan 22 at 10:28









          Andrei AkonnikauAndrei Akonnikau

          415




          415























              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.






              share|improve this answer




























                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.






                share|improve this answer


























                  0












                  0








                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 22 at 12:00









                  Vincent LuiVincent Lui

                  1126




                  1126






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Sitecore Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f16156%2fhow-can-we-work-with-geo-ip-in-local-instance%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                      How to fix TextFormField cause rebuild widget in Flutter