Umbraco 当用户发布或删除页面时,如何执行自定义代码

Umbraco 当用户发布或删除页面时,如何执行自定义代码,umbraco,umbraco7,Umbraco,Umbraco7,我想在用户发布或删除页面时运行一些代码。最好的方法是什么 我有一个自定义索引服务,可以作为html内容的搜索,所以当用户在Umbraco中发布页面时,我想向该服务提交新内容。另外,当用户删除或删除页面时,我想向索引服务提交一个delete。创建一个类并从IApplicationEventHandler插入 在OnApplicationStarting中,您可以创建所有类型的事件 像这样 public class ApplicationEventHandler : IApplicationEven

我想在用户发布或删除页面时运行一些代码。最好的方法是什么


我有一个自定义索引服务,可以作为html内容的搜索,所以当用户在Umbraco中发布页面时,我想向该服务提交新内容。另外,当用户删除或删除页面时,我想向索引服务提交一个delete。

创建一个类并从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)
        {
        }
公共类ApplicationEventHandler:IAApplicationEventHandler
{
应用程序启动时公共无效(umbraco应用程序基础umbraco应用程序,应用程序上下文应用程序上下文)
{
ContentService.Saving+=ContentService\u Saving;
ContentService.Published+=ContentService\u Published;
ContentService.UnPublishing+=ContentServiceOnUnPublishing;
ContentService.Deleting+=ContentServiceOnDeleting;
ContentService.Moved+=ContentServiceOnMoved;
MediaService.Saving+=MediaService\u Saving;
MemberService.Created+=MemberServiceOnCreated;
MemberService.Deleting+=MemberServiceOnDeleted;
}
void ContentService_Published(IPpublishingstrategy发送方,PublishEventArgs e)
{
}

非常感谢,这正是我所需要的!如何在触发发布事件的事件中获取页面Id。