Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if a HttpModule is loaded

I'm trying to find a way to programmatically check if a particular HttpModule is loaded (as a component I'm writing requires the module to work correctly). I'm trying:

bool ismodulepresent = false;
foreach(HttpModuleAction module in ((HttpModulesSection)ConfigurationManager.GetSection("system.web/httpModules")).Modules)
{ 
    if(module.Type == typeof(MyModule).FullName)
    {
        ismodulepresent = true;
        break;
    }
}

But that only works for the IIS5.1 <httpModules> section and not the newer <system.webServer> section.

Any idea if there is a better way to do this other than just checking both sections?

like image 222
Kieran Benton Avatar asked Feb 22 '09 19:02

Kieran Benton


People also ask

What is the difference between HttpModule and HTTP handler?

HttpHandler is responsible for handling http request by extension while HttpModule is responding to application life cycle events. Save this answer.

What is the difference between middleware and HttpModule?

Unlike HttpModules, there is full control of what get's executed and in what order. As they are executed in the order in which they are added. Order of middleware for responses is the reverse from that for requests. Middleware is independent of these events.

What is HttpModule?

An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.


1 Answers

HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules;
foreach (string moduleKey in modules.Keys)
{
    IHttpModule module = modules[moduleKey];
    // Do your check here
}
like image 142
Darin Dimitrov Avatar answered Sep 18 '22 01:09

Darin Dimitrov