How can I utilize or mimic Application OnStart in an HttpModule?
Posted
by Sailing Judo
on Stack Overflow
See other posts from Stack Overflow
or by Sailing Judo
Published on 2010-04-02T19:21:44Z
Indexed on
2010/04/02
19:23 UTC
Read the original article
Hit count: 269
We are trying to remove the global.asax from our many web applications in favor of HttpModules that are in a common code base. This works really well for many application events such as BeginRequest and PostAuthentication, but there is no Application Start event exposed in the HttpModule.
I can think of a couple of smelly ways to overcome this deficit. For example, I can probably do this:
protected virtual void BeginRequest(object sender, EventArgs e)
{
Log.Debug("Entered BeginRequest...");
var app = HttpContext.Current.Application;
var hasBeenSet app["HasBeenExecuted"] == null ? false : true;
if(!hasBeenSet)
{
app.Lock();
// ... do app level code
app.Add("HasBeenSet", true);
app.Unlock();
}
// do regular begin request stuff ...
}
But this just doesn't smell well to me.
What is the best way to invoke some application begin logic without having a global.asax?
© Stack Overflow or respective owner