Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question regarding IHttpModule.Dispose and Application_End

I was just reading this post "When is IHttpModule.Dispose method called?" I found this

"The Dispose method performs any final cleanup work prior to removal of the module from the execution pipeline."

which would mean it's application-wide.

It's ok. Anyway trying by myself I found out that using the IHttpModule Dispose method and an event handler for the Application.Disposed event should be barely the same. The first occurs right after the second one.

I don't feel this is 100 % correct i.e IHttpModule.Dispose is not always followed by Application_End. Let's say I have multiple instances of Application object running for my application which means each instance of Application object will have individual instances of modules inside it. Now let's assume a time comes when Application pool gets full with applications instances, what will happen then? Won't it be start disposing the application instances one by one and in the chain the modules inside the application instance will be disposed. Now this disposal of module doesn't mean that Application_End is going to fire after that. Application is still running. Am I right?

like image 723
Rocky Singh Avatar asked Jul 14 '11 19:07

Rocky Singh


1 Answers

Yes.

HttpModules are per HttpApplication. Contrary to what its name suggestion, the Application_End method in global.asax is NOT fired at the end of each HttpApplicaton's lifetime. It is fired at the end of ALL HttpApplications' lifetimes in the current AppDomain (when the AppDomain gets torn down). The same is true for the Application_Start method.

like image 179
Jeff Avatar answered Sep 28 '22 01:09

Jeff