问题
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