Sitecore Personalize 无法正常工作

标签 sitecore sitecore-dms

我为 Sitecore 的 DMS 功能创建了一个简单的演示站点。 在 sitecore 内容中,我创建了这个结构:

首页
|-个性化
..|-HomeView1
..|-HomeView2

HomeView1、HomeView2 和 Home 的模板相同,只包含一个 Field: Display Text

现在我为主页创建个性化设置,为其设置规则。 规则是当前月份是八月,并将个性化内容指向 HomeView1。 当我预览时,内容不会变成 HomeView1 的文本。 这是我的源代码:

public partial class HomePage : System.Web.UI.UserControl
{
    protected Item currentItem;
    protected void Page_Load(object sender, EventArgs e)
    {
        currentItem = Sitecore.Context.Item;
    }
}

这是我在主页上绑定(bind)的内容

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HomePage.ascx.cs" Inherits="DMSDemo.sublayouts.HomePage" %>
<div><%= currentItem["Display Text"].ToString() %></div>

我想知道为什么 Sitecore.Context.Item 在应用个性化规则时不会返回正确的项目(HomeView2)?

请给我一些建议。提前致谢。

最佳答案

当您个性化时,上下文项不会改变,子布局的数据源会。所以你应该将 currentItem 设置为数据源。

这里有一些常用代码来获取我从 Matthew Dresser's blog 复制/粘贴的数据源:

var sublayout = this.Parent as Sitecore.Web.UI.WebControls.Sublayout;
if (sublayout != null)
{
    Guid dataSourceId;
    Sitecore.Data.Items.Item dataSource;
    if (Guid.TryParse(sublayout.DataSource, out dataSourceId))
    {
        dataSource = Sitecore.Context.Database.GetItem(new ID(dataSourceId));
    }
    else
    {
        dataSource = Sitecore.Context.Database.GetItem(sublayout.DataSource);
    }
}

其他几点:

  • 一般来说,avoid the use of the context item 是一种很好的做法。
  • 您的页面项目(主页)不需要是 相同的模板具有数据源项。
  • 我不认为个性化 在预览模式下工作,但您可以在编辑模式下查看。

关于Sitecore Personalize 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31823333/

相关文章:

Sitecore FXM 问题 - 添加到占位符对话框中缺少父选择器

caching - 带有 DMS 的 Sitecore 与缓存服务器 - 您如何处理?

c# - 我如何知道哪个 DMS 规则称为 Sitecore 组件?

c# - Sitecore 多个节点用于渲染数据源

c# - 以编程方式为营销人员保存 Sitecore Web 表单

asp.net - ASP .Net 文件上传超过最大请求长度错误

content-management-system - 选择 CMS : EPiServer vs Orchard vs SiteCore vs Umbraco

azure - Azure 中的 Sitecore DMS

sitecore - 如何从 Sitecore Analytics 或 DMS 获取推荐 URL 链接