Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC PostAuthorizeRequest (and other events) not firing

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

like image 678
Steen Tøttrup Avatar asked May 12 '11 07:05

Steen Tøttrup


1 Answers

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);
}
like image 156
Darin Dimitrov Avatar answered Sep 27 '22 19:09

Darin Dimitrov