Try our conversational search powered by Generative AI!

Per Bjurström
Jan 27, 2011
  7701
(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
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024