检测 HttpModule 是否已加载

发布于 2024-07-14 12:23:09 字数 539 浏览 7 评论 0原文

我正在尝试找到一种方法来以编程方式检查是否加载了特定的 HttpModule(因为我正在编写的组件需要该模块才能正常工作)。 我正在尝试:

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

但这仅适用于 IIS5.1 部分,而不适用于较新的 部分。

除了检查这两个部分之外,是否有更好的方法来做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-07-21 12:23:09
HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules;
foreach (string moduleKey in modules.Keys)
{
    IHttpModule module = modules[moduleKey];
    // Do your check here
}
HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules;
foreach (string moduleKey in modules.Keys)
{
    IHttpModule module = modules[moduleKey];
    // Do your check here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文