加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 检测是否加载了HttpModule

发布时间:2020-12-16 04:38:15 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试找到一种方法来以编程方式检查是否加载了特定的HttpModule(作为我正在编写的组件需要模块正常工作).我尝试着: bool ismodulepresent = false;foreach(HttpModuleAction module in ((HttpModulesSection)ConfigurationManager.GetSection("system.
我正在尝试找到一种方法来以编程方式检查是否加载了特定的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< httpModules>部分而不是较新的< system.webServer>部分.

有没有想过除了检查这两个部分之外还有更好的方法来做到这一点?

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读