从 HttpModule 添加 HttpHandler 用于项目中不存在的静态文件

Add HttpHandler from HttpModule for static file not present in project

如何从 httpmodule 为项目中不存在的静态文件设置 httphandler。

例如:如果客户请求一个名为 abc.xml 的文件,那不在我的项目中,我需要从我的 httpmodule 添加处理程序并向客户发送一些响应我该怎么做。我的处理程序在从 httpmodule 添加后没有被调用。


我的 HttpModule 代码如下:

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

customHandler 中的 processrequest 没有被执行。

花了 5 小时后,明白了。

需要使用RemapHandler,

    Application.Context.RemapHandler(CustomHandler)

而不是

    Application.Context.Handler = CustomHandler