我如何找到加载的路由http模块?

时间:2009-08-23 04:56:24

标签: asp.net system.web.routing

我正在使用传统的Asp.Net网站,我在其中使用System.Web.Routing模块。我想找到我知道路由http模块是否加载的方式?

1 个答案:

答案 0 :(得分:4)

您需要知道的是模块的名称,因为您已在web.config文件中配置了该名称 例如我的名字:“UrlRoutingModule”,你可以在这里看到这个片段(格式为StackOverflow):

    <add name="UrlRoutingModule" 
         type="System.Web.Routing.UrlRoutingModule, System.Web.Routing,
         Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

一旦你有了这个,你需要做的就是检查应用程序的Modules属性(类型为HttpModuleCollection的模块名称,并验证它不是null。如果你想做一些额外的检查,你可以检查类型对象也是(未显示)。

// From Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
    if (Modules.AllKeys.Contains("UrlRoutingModules") 
        && Modules["UrlRoutingModule"] != null)
    {
        // the module is loaded
    }
}