IHttpModule Questions

J

Jonathan Wood

Greetings,

So, I now have a custom IHttpModule class that I use to establish the Theme
for each page, based on the user's settings. Seems to work just fine. Thanks
to everyone who made helpful suggestions.

The code I copied looked something like the listing below. In the Init
method, it sets a handler for PreRequestHandlerExecute. And then in the
PreRequestHandlerExecute method, it sets a handler for the page's PreInit.
The result is that I have a global handler for every pages' PreInit.

But now I'm wondering if this many layers is required. Is there any reason
to not simply set the page's theme in the PreRequestHandlerExecute method,
and eliminate the PreInit handler? It even seems like all my session and
membership data is available during PreRequestHandlerExecute (although some
of my database data is cached in the Session object). How would I determine
if I need the PreInit handler?

Thanks.

public class ThemeManager : IHttpModule
{
public ThemeManager()
{
}

public void Init(HttpApplication app)
{
app.PreRequestHandlerExecute += new
EventHandler(Context_PreRequestHandlerExecute);
}

void Context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
page.PreInit += new EventHandler(Page_PreInit);
}

void Page_PreInit(object sender, EventArgs e)
{
Page page = (Page)sender;
// Set page theme here!
}

public void Dispose()
{
}
}

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top