【发布时间】:2012-02-06 15:38:13
【问题描述】:
考虑一个包含以下httpHandlers 声明的Web.config 文件:
<httpHandlers>
<add verb="*" path="*" type="MyWebApp.TotalHandlerFactory"/>
</httpHandlers>
换句话说,这个处理程序工厂想要“看到”所有传入的请求,以便有机会处理它们。但是,它不一定要实际处理所有这些,只需要满足特定运行时条件的那些:
public sealed class TotalHandlerFactory : IHttpHandlerFactory
{
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
if (some condition is true)
return new MySpecialHttpHandler();
return null;
}
public void ReleaseHandler(IHttpHandler handler) { }
}
但是,这样做会完全覆盖默认的 ASP.NET 处理程序,这意味着 ASP.NET 页面和 Web 服务不再工作。对于每个不满足“if”中“某些条件”的 URL,我只会得到一个空白页面。因此,似乎返回null 是错误的做法。
那么我需要返回什么,以便仍然可以正常处理 ASP.NET 页面和 Web 服务?
【问题讨论】:
-
我意识到它是 HttpHandlerFactory 而不是处理程序本身。
标签: asp.net ihttphandler httphandlerfactory