Creating a job that runs every time any publish is made

Vote:
 

Hello!

I cannot find any other problem relating to this query.

Im looking to create an action which runs every time a page is published. 

Here I will get the page info etc.

Is there any sort of functionality that exists in Episerver for this?

Thanks!!

#216198
Jan 29, 2020 16:01
Vote:
 

Hi!

You can subscribe to episerver events and react on content change(eg publish). Check this out: https://world.episerver.com/blogs/Daniel-Ovaska/Dates/2019/6/content-events-in-episerver/

#216201
Edited, Jan 29, 2020 16:21
Jack - Jan 29, 2020 17:09
Thanks very much for the help here
Vote:
 

Hi Jack,

Yes, you can tie into content events for this purpose. The easiest way is to create an IInitializableModule and, in the "Initialize" method, attach to whichever events you want to listen for (e.g. PublishedContent) like this:

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class PageEventInit : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
        contentEvents.PublishedContent += ContentPublishing;
    }

    private void ContentPublishing(object sender, ContentEventArgs e)
    {
        // Do stuff here - content which triggered the event is in e.Content
    }

    public void Uninitialize(InitializationEngine context)
    {
        var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
        contentEvents.PublishedContent -= ContentPublishing;
    }
}
#216204
Jan 29, 2020 17:52
Paul Gruffydd - Jan 29, 2020 17:54
Sorry, there's something weird going on with the forum. This question appeared as unanswered until I posted a response.
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.