Here is a quick tips to get the list of all active HTTPModules at runtime. We can get the list of all HttpModules from the web.config or from machine.config file. But, what we need to do if we want to get the list of all active HttpModules during runtime? Yes. We can easily get the details with the help of HttpApplication and HttpModuleCollection Class. If we quickly recall the IIS Process Request [One detailed Article], when a request reaches to worker Process from client browser, First of all Worker process is responsible to start and HttpRuntime by loading ISAPI filter. After that HttpRuntime load an HttpApplication object with the help of HttpApplicationFactory class. Each and every request should pass through the corresponding HTTPModule to reach to HTTPHandler, this list of module are configured by the HTTPApplication. Below is the code snippet by which we can get the list of active HttpModules.
//Get Application Instance from Current Content HttpApplication httpApps = HttpContext.Current.ApplicationInstance; //Get List of modules in module collections HttpModuleCollection httpModuleCollections = httpApps.Modules; Response.Write("Total Number Active HttpModule : " + httpModuleCollections.Count.ToString() + "</br>"); Response.Write("<b>List of Active Modules</b>" + "</br>"); foreach (string activeModule in httpModuleCollections.AllKeys) { Response.Write(activeModule + "</br>"); }
Below is the sample output :
This can be quite useful when we want to check if our custom created module loaded successfully or not .
Good One .Nice Tip
LikeLike
Thanks dude !!
LikeLike
Good One! Abhijit…..
LikeLike
a very Nice tip thanks dude!
LikeLike
Thanks man !
You may like my new web site
http://dailydotnettips.com/.
It’s underdevelopment. Will launch it very very soon !!
LikeLike
Thanks,
I have a related question : Can we modify the list of active modules ? like registering a new one based on some condition ?
LikeLike
Thanks Anas !
You want to mean activting or deactivating some module at runtime ?
LikeLike
Hi Abhi, great post
LikeLike
Thanks
LikeLike
Very nice
LikeLike
Thanks Kirti !!
LikeLike
Hi,
@You want to mean activting or deactivating some module at runtime ?
Yes and without modifying the web.config file (without restarting the app).
Do you have any idea if it’s possible ?
Thank you!
LikeLike
Anas,
Have a look into this,
Config-free IHttpModule Registration
LikeLike
Great,
Exactly what I’m looking for.
Thank you !
LikeLike
Hi Abhijit,
Nice one. It can be really very useful in some of the specific requirements of the applications.
Regards,
Sandeep Ramani
LikeLike
Thanks Sandeep !
LikeLike
you rock
LikeLike
🙂
LikeLike
There are mistape: foreach (string activeModule inttpModuleCollections.AllKeys)
should be: foreach (string activeModule in httpModuleCollections.AllKeys)
LikeLike
Updated !!
Thanks !
LikeLike