The MSDN documentation says:
HttpContext.RemapHandler Method – Enables you to specify a handler for the request.
I am trying to move the processing of the request from one handler to another depending on a condition in the first handler. The HttpContext.RemapHandler method seems to initialise an instance of the second handler but not call the HttpHandler.ProcessRequest method; the response is empty.
Does the HttpContext.RemapHandler method do what I think it should – transfer processing to a new HttpHandler and calling the HttpHandler.ProcessRequest method? Or should I be using another approach such as another method or an HttpModule?
EDIT:
Turns out I should be using a HTTPHandlerFactory. I have the solution working nicely now.
So what exactly is HttpContext.RemapHandler for?
You can use
HttpContext.RemapHandleras you specified, however if anotherHttpHandlercallsRemapHandler(e.g. ASP.NET MVC which registersMvcHandlerinPostResolveRequestCache) yourIHttpModulewill never fire. This is maybe whyIHttpHandler.Processwas never called.If this is your issue, you can simply define a route to ignore in
MvcApplication.RegisterRouteslike this:Also, remember that with Visual Studio Web Development Server and IIS6,
RemapHandlerwill not work.Here is an example of how to select the right way to remap the handler based on whether or not Integrated Pipeline is activated AND still be able to access the session:
The difference between using a
HttpHandlerFactoryandHttpModulein this case is that the latter allows you to decide when to use whichIHttpHandlerregardless of ASP.NETIHttpHandlermappings. More on MSDN: HTTP Handlers and HTTP Modules Overview.