考慮一個Web.config
文件包含以下httpHandlers
聲明:如何獲取對默認ASP.NET頁面處理程序或Web服務處理程序的引用?
<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」條件的網址獲得一個空白頁面。因此,似乎返回null
是不對的。
那麼我需要返回什麼,以便ASP.NET頁面和Web服務仍能正常處理?
我意識到它是HttpHandlerFactory不是處理程序本身。 – Aliostad 2012-02-06 15:55:53