How to Hook Into The Episerver CMS Events Pipeline

A common requirement when working with Episerver is to add custom functionality into the page’s events, for example, you may need to run custom code when you save, delete or move content. One example that springs to mind, is re-indexing your website’s search index.

Luckily for us, Episerver provides a very easy provider called the Content Event provider to allow us to perform these sorts of tasks.


In order to hook into Episerver CMS events, you will need to create an initialization module. If you have never come across one of these before, then I would recommend that you read this article first.

We access the Content Events Provider the same way we do with any other Episerver API, via the ServiceLocator, like so:

var events = ServiceLocator.Current.GetInstance<IContentEvents>();

After you have access to the content events provider, you will have access to override a number of very useful events that get triggered within the CMS, like the PublishedContent, DeletingContent, MovedContent and SavingContent events to name a few.

You can see a full list of all the events you can hook into here

So let’s take a look at the code we need to do this:

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)
EventsPublishedContent(object sender, ContentEventArgs e)
/// Do stuff here

NOTE You can also hook into Episerver commerce events the same way, as long as you add the:


Within the ModuleDependency attribute. The code above is pretty simple, we create an initialization module, call ServiceLocator with IContentEvents and then register the events you are interested in.

Once you have your events registered the methods will be hit when a content editor tries to perform one of the matching options. One standard thing you will very likely need to do is get access to the Episerver page or block that is attempting to be modified. There are several ways of doing this:

private void EventsPublishedContent(object sender, ContentEventArgs e) 
var repo = ServiceLocator.Current.GetInstance<IContentRepository>(); 
var content = repo.Get<IContent>(e.ContentLink); 

This snippet will give you access to the objects IContent properties. If you want the whole object you can simply type it yourself like this:

var pageType = eventArgs.Content as EpiPageType;


In today’s guide, we’ve talked about how you can hook into the Episerver CMS event pipeline. If you create an InitializationModule and use IContentEvents you can get access to a number of very useful events, like hooking into the Saving, Updating and Deleting event handlers.

When you get into your code you will very likely want to get access to the object being manipulated. You can use the ContentEventArgs to get access to it.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

9 replies
  1. James Wilkinson
    James Wilkinson says:

    Thanks Jon, useful article.
    Do you know of any ways of hooking into the CMS login event? I.e. so when a user logs in to the CMS I want to execute some code (e.g. fire an email – “user x just logged into the CMS”?

    Cheers 🙂

    • Jon D Jones
      Jon D Jones says:

      It all depends on how you implement your membership and architect your registration/log-in. If you’re using the out-of-the-box one, you could extend the membership provider and hook into the on successful log-in method depending on your requirements The other way is to create your own log-in block and put all the logic in your code after checking for success/failure. My advice with this is to follow the standard .NET advice, as EPi doesn’t change that much

  2. Mårten Andersson
    Mårten Andersson says:

    Do you know if there is a event that is available when drag n dropping content to a content area?

    what the question is, is that can you when i for example drag and drop a MediaFile to a ContentArea override the default creation and create a block instead for creating a link/contentreference to that image?

    FYI awesome blog, learned one or two things of your blog.


Trackbacks & Pingbacks

  1. […] To finish off this tutorial, I’ll quickly add the code examples for the page publishing event listener and the scheduled task code. If this code is unfamailair with you then I suggest that you read, How To Set-Up A Scheduled Task In Sitecore and How to Hook Into The Episerver CMS Events Pipeline . […]

  2. […] have talked previously in, How to Hook Into The EpiServer CMS Events Pipeline about the EpiServer event pipeline. When we work with EpiServer content, a number of events are […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *