Sitecore Velocity如何构建Item的URL

时间:2012-11-12 14:10:44

标签: sitecore sitecore6 sitecore-workflow

我使用以下代码可视化电子邮件中的不同信息。

   this.velocityContext.Put("args", args);
            this.velocityContext.Put("item", args.DataItem); 
            this.velocityContext.Put("processor", args.ProcessorItem);
            this.velocityContext.Put("user", Context.User); 
            this.velocityContext.Put("history", args.DataItem.State.GetWorkflow().GetHistory(args.DataItem));
            this.velocityContext.Put("state", args.DataItem.State.GetWorkflowState());
            this.velocityContext.Put("nextState", this.GetNextState(args));
            this.velocityContext.Put("site", Context.Site);
            this.velocityContext.Put("time", DateTime.Now);
            this.velocityContext.Put("previewUrl",string.Format("Http://{0}/?sc_itemid=%7b{1}%7d&sc_mode=preview",Context.Site.HostName,args.DataItem.ID.Guid));

previewUrl的值无效。 Context.Site.HostName始终为null。 有人知道会是什么原因吗?或者是否有其他方式来构建文章的链接,内容所有者必须对其进行审核/批准或拒绝?

谢谢,

1 个答案:

答案 0 :(得分:0)

如果您的代码在工作流程中执行,它将在Shell站点上下文中执行,这不会为您提供您正在寻找的站点上下文或主机名。您需要解析该项所属的站点,并从中获取主机名。

从这里抓取LinkHelper类: http://webcmd.wordpress.com/2011/11/30/multiple-sites-with-one-authoring-domain-in-sitecore/

使用LinkHelper确定给定项目的站点。然后从返回的SiteInfo中获取HostName。