Per Bjurström
Jan 27, 2011
  7822
(3 votes)

Initialize HTTP events in a module

EPiServer CMS 6 and Community 4 introduced a new approach to initialization, read more about it here.

We are adding infrastructure for subscribing to HTTP events in the R2 wave with the new IInitializableHttpModule interface which is defined like this:

public interface IInitializableHttpModule : IInitializableModule
{
void InitializeHttpEvents(HttpApplication application);
}

Every time a new HttpApplication is being initialized this interface will let you participate and listen to events. Do remember that this is an initializer interface, there will only be one instance of your initializer but there will be many HttpApplication instances being initialized. The use case for this interface is to able to deploy modules without adding adding an HTTP Module in web.config.

A skeleton module to use the new interface:

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class MyInitialization : IInitializableHttpModule
{
public void InitializeHttpEvents(HttpApplication application)
{
application.BeginRequest += application_BeginRequest;
}

public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
DataFactory.Instance.PublishedPage += Instance_PublishedPage;
}

public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
DataFactory.Instance.PublishedPage -= Instance_PublishedPage;
}

public void Preload(string[] parameters)
{
}

void Instance_PublishedPage(object sender, PageEventArgs e)
{
//implementation
}

void application_BeginRequest(object sender, EventArgs e)
{
//implementation
}
}

Jan 27, 2011

Comments

Jan 27, 2011 02:14 PM

Nice!
Also: adding adding ;)

Please login to comment.
Latest blogs
Creating an Optimizely CMS Addon - Adding an Editor Interface Gadget

In   Part One   of this series, I covered getting started with creating your own AddOn for Optimizely CMS 12. This covered what I consider to be an...

Mark Stott | Aug 30, 2024

Configure your own Search & Navigation timeouts

The main blog Configure your own Search & Navigation timeouts was posted for years but you need copy the code to your application. We now bring tho...

Manh Nguyen | Aug 30, 2024

Joining the Optimizely MVP Program

Andy Blyth has been honoured as an Optimizely MVP, recognising his contributions to the Optimizely community. Learn how this achievement will enhan...

Andy Blyth | Aug 29, 2024 | Syndicated blog

Welcome 2024 Summer OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Aug 29, 2024

Create custom folder type in Edit Mode

Content Folders, which are located in assets pane gadget or multichannel content gadget, allow you to add any type of block or folders. But...

Grzegorz Wiecheć | Aug 28, 2024 | Syndicated blog

Creating an Optimizely AddOn - Getting Started

When Optimizely CMS 12 was launched in the summer of 2021, I created my first AddOn for Optimizely CMS and talked about some of the lessons I learn...

Mark Stott | Aug 28, 2024