I was surprised that in MvcApplication.Init the Modules collection only has one entry in it, named “__ASP_IntegratedDynamicModule_Shim”. In my webforms app, there were about 13 modules, one of which was “FormsAuthentication”.
In my webforms app, I override HttpApplication.Init, then use Modules[“FormsAuthentication”] to grab the FormsAuthenticationModule and wire up to its Authenticate event in order to substitute my own handler. I’m not sure how to do this now that I’m moving to MVC 3.
The forms auth module is clearly running in my pipeline, because authentication mode=”forms” is working fine (I can log in and out using the standard FormsAuthentication techniques). I’m using IIS 7 with an integrated ASP.NET 4.0 pipeline.
Anybody else notice this? I’m probably just doing something really dumb…
In the integrated pipeline, your Init() method will run multiple times. Due to the way MVC 3 hooks itself into the ASP.NET pipeline, the very first call to Init() might contain an empty module collection. Subsequent calls should contain the module you’re looking for.
I’d recommend modifying your Init() code to say if Modules[“FormsAuthentication”] doesn’t exist, no-op. Your code will eventually be called again, and you’ll eventually be able to hook that event.