Wednesday, January 16, 2013

Get the list of all HttpModules in ASP.Net

Here I will give you a quick trick to get the list of all active HttpModules at runtime. We can get all the HttpModules from web.config or from machine.config file. But, If we want this at runtime then we can do this with the help of HttpApplication and HttpModuleCollection class. Below is the code snippet for getting the list of all active  HttpModules
.

//Get Application Instance from Current Content
HttpApplication httpApps = HttpContext.Current.ApplicationInstance;

//Get List of modules in module collections
HttpModuleCollection httpmodules = httpApps.Modules;
           
Response.Write("Total Number Active HttpModule : " + httpmodules.Count.ToString() + "</br>");           
Response.Write("<b>List of Active Modules</b>" + "</br>");
           
foreach (string activeModule in httpmodules.AllKeys)           
{               
    Response.Write(activeModule + "</br>");           
}

Below is the sample output-
kick it on DotNetKicks.com

No comments:

Post a Comment

^ Scroll to Top