我想在用户发布或删除页面时运行一些代码。最好的方法是什么?
我有一个自定义索引服务,可以搜索html内容,所以当用户在Umbraco中发布页面时,我想向该服务提交新内容。此外,当用户删除或页面时,我想向索引服务提交删除。
创建一个类并从IApplicationEventHandler中导入在OnApplicationStarting中,您可以创建所有类型的事件
像这个
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)
{
}