我想在用户发布或删除页面时运行一些代码。这样做的最佳方式是什么?
我有一个自定义索引服务,可用作搜索html内容,因此当用户在Umbraco中发布页面时,我想向此服务提交新内容。另外,我想在用户删除或分页时向索引服务提交删除。
答案 0 :(得分:0)
创建一个类并从ApplicationEventHandler继承 在OnApplicationStarted中,您可以创建所有类型的事件
喜欢这个
public class ApplicationEventHandler : IApplicationEventHandler
{
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Saving += ContentService_Saved;
ContentService.Published += ContentService_Published;
ContentService.UnPublishing +=ContentServiceOnUnPublishing;
ContentService.Deleting += ContentServiceOnDeleting;
ContentService.Moved +=ContentServiceOnMoved;
MediaService.Saving+=MediaService_Saving;
MemberService.Created+=MemberServiceOnCreated;
MemberService.Deleting += MemberServiceOnDeleted;
}
void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
}