jump to navigation

How to get list of all active HttpModules in ASP.NET? June 8, 2010

Posted by Abhijit Jana in ASP.NET.
Tags:
trackback

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 .

Shout it

Comments»

1. DotNetShoutout - June 8, 2010

How to get list of all active HttpModules in ASP.NET? « Abhijit’s World of .NET…

Thank you for submitting this cool story – Trackback from DotNetShoutout…

2. sashidhar - June 10, 2010

Good One .Nice Tip

Abhijit Jana - June 10, 2010

Thanks dude !!

3. Subhendu De - December 17, 2010

Good One! Abhijit…..

4. Husam Khoulah - December 21, 2010

a very Nice tip thanks dude!

Abhijit Jana - December 21, 2010

Thanks man !

You may like my new web site
http://dailydotnettips.com/.

It’s underdevelopment. Will launch it very very soon !!

5. Anas Ghanem - December 21, 2010

Thanks,
I have a related question : Can we modify the list of active modules ? like registering a new one based on some condition ?

Abhijit Jana - December 22, 2010

Thanks Anas !

You want to mean activting or deactivating some module at runtime ?

6. abhi_viking - December 21, 2010

Hi Abhi, great post

Abhijit Jana - December 22, 2010

Thanks

7. Kirti Darji - December 22, 2010

Very nice

Abhijit Jana - December 22, 2010

Thanks Kirti !!

8. Anas Ghanem - December 22, 2010

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!

Abhijit Jana - December 22, 2010

Anas,

Have a look into this,
Config-free IHttpModule Registration

Anas Ghanem - December 23, 2010

Great,
Exactly what I’m looking for.
Thank you !

9. Ramani Sandeep - December 22, 2010

Hi Abhijit,

Nice one. It can be really very useful in some of the specific requirements of the applications.

Regards,
Sandeep Ramani

Abhijit Jana - December 22, 2010

Thanks Sandeep !

10. pranay rana - December 23, 2010

you rock

Abhijit Jana - December 23, 2010
11. Edu - December 23, 2010

There are mistape: foreach (string activeModule inttpModuleCollections.AllKeys)
should be: foreach (string activeModule in httpModuleCollections.AllKeys)

Abhijit Jana - December 23, 2010

Updated !!

Thanks !

12. My Blog 2010 in review by WordPress.Com « Abhijit's World of .NET - January 2, 2011

[...] The busiest day of the year was December 22nd with 1 views. The most popular post that day was How to get list of all active HttpModules in ASP.NET?. [...]

13. How to retrieve HTTPModule details from HttpModuleCollection ? « Abhijit's World of .NET - May 23, 2011

[...] one of my previous post I have talked about How to get list of all active HttpModules in ASP.NET? Where I have explained how we can get list of all active modules of an ASP.NET Application at [...]

14. How to retrieve HTTPModule details from HttpModuleCollection ? - Abhijit's Blog - May 24, 2011

[...] one of my previous post I have talked about How to get list of all active HttpModules in ASP.NET? Where I have explained how we can get list of all active modules of an ASP.NET Application at [...]

15. How to retrieve HTTPModule details from HttpModuleCollection ? - Daily .Net Tips - May 25, 2011

[...] in .NET, ASP.NET, Tips Author : Abhijit Tweet In one of my previous post I have talked about How to get list of all active HttpModules in ASP.NET? Where I have explained how we can get list of all active modules of an ASP.NET Application at [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,265 other followers