欺骗IP地址以测试Sitecore 8的GEOIP查找

Sut*_*han 3 sitecore sitecore-dms sitecore8

我是Sitecore的新手.我正在尝试实现以下流程类来覆盖GeoIP值以进行测试.

我找不到类跟踪器所在的命名空间.请注意,我使用的是localhost上托管的Sitecore 8.Sitecore博客:@sitecorejohn博客

有人可以帮我解决这个命名空间问题.

谢谢.

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());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*lak 5

Trackerclass在Sitecore.Analytics命名空间中.

确保您的项目引用Sitecore.Analytics.dll.

Sitecore 8中,您应该使用Tracker.CurrentTracker.Current.Interaction不是Tracker.CurrentVisit:

Tracker.Current.Interaction.Ip = address.GetAddressBytes();
Tracker.Current.Interaction.UpdateGeoIpData(optionalTimeout);
Run Code Online (Sandbox Code Playgroud)

您可以考虑CreateVisitXForwardedFor处理器和调用之后添加另一个处理器到管道:

args.Interaction.Ip = address.GetAddressBytes();
Run Code Online (Sandbox Code Playgroud)

您不必打电话UpdateGeoIpData- 它将在UpdateGeoIpData处理器中自动调用.