从HttpContext在Web.Config中获取已注册的HttpHandlers

Dan*_*ite 8 asp.net

有没有办法IHttpHandler从当前HttpContext或web.config 获取已注册的s 的类型?

我试图看看我HttpHandler是否在web.config中注册了WebControl.

Ofe*_*lig 5

您可以通过HttpHandler以下方式从web.config 获取已注册的列表:

using System.Configuration;
using System.Web.Configuration;

Configuration cfg = WebConfigurationManager.OpenWebConfiguration("/");
HttpHandlersSection hdlrs = (HttpHandlersSection)cfg.GetSection("system.web/httpHandlers");
Run Code Online (Sandbox Code Playgroud)

  • 这实际上不适用于自定义处理程序.运行上面的代码我获得了所有的库存处理程序,但我的自定义处理程序没有显示在处理程序列表中.您还需要检查(system.webServer/handlers),具体取决于应用程序是在IIS 7还是之前运行. (3认同)