如何从 Sitecore 地理位置信息获取用户所在的国家/地区?



我有一个使用Sitecore 7.5构建的Sitecore解决方案。我们还从Sitecore应用程序中心购买了Sitecore IP地理定位服务。一旦所有这些都运行起来,我如何在代码中访问当前用户的国家?我似乎找不到任何文档来告诉我如何获得任何地理位置信息。

谢谢,科里

我假设您已经启用了Analytics。试试这个:

Sitecore.Analytics.Tracker.Current.Interaction.GeoData.Country

现在看起来是这样做的:

Sitecore.Analytics.Lookups.LookupManager.GetInformationByIp(string ip);

简单格式:

Sitecore.Analytics.Lookups.MaxMindProvider maxMindProvider = new Sitecore.Analytics.Lookups.MaxMindProvider();
Sitecore.Analytics.Lookups.WhoIsInformation geoIpInformation = maxMindProvider.GetInformationByIp(Request.ServerVariables["REMOTE_ADDR"]);
string country = geoIpInformation.Country;
与缓存:

System.Net.IPAddress ipAddress = null;
if (System.Net.IPAddress.TryParse(Request.ServerVariables["REMOTE_ADDR"], out ipAddress))
{
    Sitecore.Analytics.Lookups.GeoIpOptions geoIpOptions = new Sitecore.Analytics.Lookups.GeoIpOptions();
    geoIpOptions.Ip = ipAddress;
    geoIpOptions.MillisecondsTimeout = 1000;
    Sitecore.Analytics.Lookups.GeoIpResult geoIpResult = Sitecore.Analytics.Lookups.GeoIpManager.GetGeoIpData(geoIpOptions);
    if (geoIpResult != null)
    {
        string country = geoIpResult.GeoIpData.Country;
    }
}

来源:http://wiki.evident.nl/Sitecore%20MaxMind%20GeoIP%20api%20and%20cachinig.ashx?AspxAutoDetectCookieSupport=1

https://doc.sitecore.net/sitecore_experience_platform/80/ip_geolocation/setting_up_sitecore_ip_geolocation你也可以试试sitecore 8网站

相关内容

最新更新