MvcApplication.Modules is surprisingly empty in MVC 3

I was surprised at MvcApplication. There is only one entry in the module collection called "__ASP_IntegratedDynamicModule_Shim". There were about 13 modules in my webforms application, one of which was “FormsAuthentication”.

In my webforms application, I override HttpApplication.Init, then use the ["FormsAuthentication"] modules to capture the FormsAuthenticationModule module and hook into its Authenticate event to replace my own handler. I am not sure how to do this now when I move to MVC 3.

The auth forms module explicitly works in my pipeline because the authentication mode = "forms" works fine (I can enter and exit using standard FormsAuthentication methods). I am using IIS 7 with the integrated ASP.NET 4.0 pipeline.

Has anyone else noticed this? I’m probably just doing something really dumb ...

+4
source share
1 answer

In the integrated pipeline, your Init () method will execute several times. Due to the way MVC 3 hooks itself in the ASP.NET pipeline, the very first call to Init () may contain an empty collection of modules. Subsequent calls should contain the module you are looking for.

I would recommend changing the Init () code to say if there are no modules ["FormsAuthentication"], no-op. Ultimately, your code will be called, and you will eventually be able to hook this event.

+2
source

Source: https://habr.com/ru/post/1332701/


All Articles