0
votes

I would like to run some code when a user publishes or deletes a page. What is the best way to do this?

I have a custom index service that works as a search for html content, so I would like to submit new content to this service when a user publishes a page in Umbraco. Also I would like to submit a delete to the index service when a user deletes or pages.

1

1 Answers

0
votes

Create a class and inhert from IApplicationEventHandler in the OnApplicationStarting you can create all kind of events

Like this

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)
        {
        }