Search code examples
asp.nethttphandlerhttpmodule

Add HttpHandler from HttpModule for static file not present in project


How to set httphandler from httpmodule for static file that is not present in poject.

Eg: If client requests a file called abc.xml thats not in my project,I need to add handler from my httpmodule and send some response to client how do i do it. My handler does not get called after adding it from httpmodule.


My HttpModule Code is as given below:

Public Sub Context_BeginRequest(sender As Object, e As EventArgs)
 Dim Application As HttpApplication = CType(sender, HttpApplication)
 Dim CustomHandler As StorageHandler = New StorageHandler()
 Application.Context.Handler = CustomHandler
End Sub

The processrequest in customHandler does not get executed.


Solution

  • After spending good 5hr, Got it .

    Need to use RemapHandler,

        Application.Context.RemapHandler(CustomHandler)
    

    and not

        Application.Context.Handler = CustomHandler