Registering Page Event Handlers in EPiServer

by matt 18. June 2009 17:04

I’ve been working on a couple of things lately in EPiServer that I want to be able to easily re-use on other projects.  From my point of view that means just dropping DLLs in folders and letting EPiServer do as much of the work as possible.  One of my little pieces  of functionality needs to happen when a page has been published.  There are a couple of ways to do this, and previously I have been doing it in globla.ascx.  Today I cam across an blog by Allen Thraen on discussing the subject of how to register DataFactory event handlers in EPiServer which describes in much better detail than I can about the different methods that can be used.

I ended up using the last method he mentions as I find it the cleanest way forward.  I would copy the code in here, but you should go read his blog about it in honesty as its full of interesting stuff as always.  The key point is that any class that inherits from EPiServer.PlugIn.PlugInAttribute and has a void Start() method will be called by EPiServer in the plug-in loading mechanism.

The thing to keep in mind is that (as per Allen’s example code), if you register a PublishedEvent handler, it will happen when any page is published.  That being the case, you’ll need to be inventive with filtering your exact requirements in the event handler making sure that you only do what you want when you want to!  Common sense I suppose. 

I then got to thinking, “Hey, if I can do this then how messy is this potentially going to get if anyone can register and event handler?”.  It would be pretty difficult to get a handle on what is going on.  Luckily, Andres Hattestad has got a solution for this that reports which events are registered, and where.  I’m trying that out just now, but I’m pretty certain it’s going to be awesome and make my life a lot easier over the coming weeks, as I have a lot of plug-ins that I want to build.

I strongly suggest that you going and read Anders’s and Allen’s posts and adorn them with due praise for being clever and of a sharing nature :)

Tags:

CMS | EPiServer

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar