Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

In EpiServer 8, how can I override the publish/save event?

Vote:
 

We are working with EpiServer 8, and have a scenario where we use web page monitoring solution to detect unauthorized content changes.  The monitor uses a REST API, where we can inform the monitor of a "maintenance period" so that it treats changes made during the maintenance period as authorized.

To solve this problem, our thought is to write code that gets triggered when the EpiServer CMS changes are publshed, or scheduled to be published.  When a publish starts, we need to notify the monitor that a new maintenance period has started, and when the publish ends, we need to let the monitor know that the maintenance has ended.

How can I go about doing this?  Some preliminary research led me to a 5-year old thread.  But I was unable to locate any current approaches for this.  Thanks for your help.

#149845
Jun 08, 2016 17:47
Vote:
 

You can easily add custom logic to all content events like published or saved etc.

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule)]
public class EventsInitialization : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        var events = ServiceLocator.Current.GetInstance<IContentEvents>();
        events.PublishedContent += EventsPublishedContent;
    }
 
    public void Preload(string[] parameters)
    {
    }
 
    public void Uninitialize(InitializationEngine context)
    {
    }
 
    private void EventsPublishedContent(object sender, ContentEventArgs e)
    {
        //Create audit, log stuff...call REST service...
    }
}

There are quite a few events that you can react to. Published, Moved and Deleted are the most useful...

#149846
Edited, Jun 08, 2016 18:14
Vote:
 

Thanks for your help Daniel. With your guidance, this was easy to find for the immediate publish event option. For the immediate publish, I'm intercepting the events.PublishingContent event.

What about scheduled publishing? When a scheduled publishing event is saved, I'll need to save a notification to our web page monitoring solution as well. What event in EpiServer can I react to which will have the scheduled publish time? Thanks.

#150234
Jun 14, 2016 14:56
Vote:
 

Should be the same. Haven't tested it but it should be the same or I would regard it as a bug.

Happy coding!

#150235
Jun 14, 2016 15:04
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.