I'm working on the mvcForum project (on codeplex) and want to remove as much code as possible from the global.asax file - mostly to make it easier to integrate mvcForum into existing ASP.NET MVC application without changing too much code.
I need to hook into the application events to be able to set the correct CultureInfo (depending on the users' choice etc) and other things.
This isn't a problem with this in the global.asax file:
protected void Application_PostAuthorizeRequest() {
// Some code here!
}
But when I try moving the code somewhere else, the event never happens. What I'm doing is this:
public MVCForumBootstrapper(HttpApplication app) {
app.PostAuthorizeRequest += new EventHandler(app_PostAuthorizeRequest);
}
And this in the global.asax
protected void Application_Start() {
var strapper = new MVCForumBootstrapper(this);
}
I was kind of expecting this to work in exactly the same way?
What am I doing wrong/have I missed?
Thanks, Steen
You should do this in the Init
method of Global.asax. In Application_Start
it's too late too hook events:
public override void Init()
{
base.Init();
var strapper = new MVCForumBootstrapper(this);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With