根据你要使用这个日期,或许稍微不同的方法可能会更好。以前的答案是有效的,可能会工作得很好。但在发布时更新主数据库可能会让发布引擎认为主项目已更改并需要重新发布。 (EventDisabler等可以防止这种情况发生,也可以触发重新索引,等等......事情可能会变得非常棘手)
或者,您可以改为在Web数据库中的项目上编写发布日期。
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<publishItem>
<processor type="Sitecore.Publishing.Pipelines.PublishItem.PerformAction, Sitecore.Kernel">
<patch:attribute name="type">Your.Namespace.PerformAction, Your.Assembly</patch:attribute>
</processor>
</publishItem>
</pipelines>
</sitecore>
</configuration>
和实施与此类似:
public class PerformAction : Sitecore.Publishing.Pipelines.PublishItem.PerformAction
{
public override void Process(PublishItemContext context)
{
base.Process(context);
if (context.Aborted || context.VersionToPublish == null || context.VersionToPublish.Source == null)
return;
var target = context.PublishOptions.TargetDatabase.GetItem(context.VersionToPublish.ID, context.VersionToPublish.Language);
if (target == null)
return;
using (new EditContext(target, false /*updateStatistics*/, true /*silent*/))
{
DateField lastPublished = target.Fields["LastPublished"]
lastPublished.Value = Sitecore.DateUtil.IsoNo;
}
}
}
约翰西方有一个博客帖子这个位置:
http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2011/08/intercept-item-publishing-with-the-sitecore-aspnet-cms.aspx
具有存储在Web数据库中的发布日期,你可以从那里读取它,或者为主数据库创建一个计算索引字段,而不是来自Web数据库的日期。
这可能是一个更强大的解决方案,但它又取决于您使用该字段的内容,以及您是否正在控制读取该值的代码。