Detecting if a HttpModule is loaded

℡╲_俬逩灬. 提交于 2019-12-09 16:04:17

问题


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?


回答1:


HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules;
foreach (string moduleKey in modules.Keys)
{
    IHttpModule module = modules[moduleKey];
    // Do your check here
}


来源:https://stackoverflow.com/questions/575598/detecting-if-a-httpmodule-is-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!