Spoof an IP address to test GEOIP lookups with Sitecore 8

扶醉桌前 提交于 2019-12-12 16:55:47

问题


I am new to Sitecore. I'm trying to implement following process class to overwrite GeoIP values for testing purpose.

I can't find in which namespace the class Tracker is situated. Please note that I am using Sitecore 8 hosted on localhost. Sitecore Blog: @sitecorejohn blog

Can some one please help me to resolve this namespace issue.

Thanks.

namespace Sitecore.Sharedsource.Analytics.Pipelines.StartTracking
{
    using System.Net;

    using Sitecore.Analytics;
    using Sitecore.Analytics.Pipelines.StartTracking;

    public class OverrideIPAddress
    {
        public void Process(StartTrackingArgs args)
        {
            if (Tracker.CurrentVisit == null
              || Tracker.CurrentVisit.GeoIp == null
              || Tracker.CurrentVisit.Ip == null)
            {
                return;
            }

            string ip = new IPAddress(
              Tracker.CurrentVisit.GeoIp.Ip).ToString();

            if (ip != "0.0.0.0" && ip != "127.0.0.1")
            {
                return;
            }

            string html = Sitecore.Web.WebUtil.ExecuteWebPage(
              "http://www.whatismyip.com/automation/n09230945.asp");
            IPAddress address = IPAddress.Parse(html);
            Tracker.CurrentVisit.GeoIp =
              Tracker.Visitor.DataContext.GetGeoIp(address.GetAddressBytes());
        }
    }
}

回答1:


Tracker class is in the Sitecore.Analytics namespace.

Make sure that your project references Sitecore.Analytics.dll.

In Sitecore 8 you should use Tracker.Current and Tracker.Current.Interaction instead of Tracker.CurrentVisit:

Tracker.Current.Interaction.Ip = address.GetAddressBytes();
Tracker.Current.Interaction.UpdateGeoIpData(optionalTimeout);

You can consider adding another processor to CreateVisit pipeline after XForwardedFor processor and call:

args.Interaction.Ip = address.GetAddressBytes();

You won't have to call UpdateGeoIpData - it will be called automatically in the UpdateGeoIpData processor.



来源:https://stackoverflow.com/questions/31453081/spoof-an-ip-address-to-test-geoip-lookups-with-sitecore-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!