从HttpModule添加HttpHandler,以获取项目中不存在的静态文件

时间:2017-11-07 07:52:17

标签: asp.net httphandler httpmodule

如何设置httpsodule中的httphandler以获取poject中不存在的静态文件。

例如:如果客户端请求不在我的项目中的名为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不会被执行。

1 个答案:

答案 0 :(得分:0)

花了5小时后,明白了。

需要使用RemapHandler,

    Application.Context.RemapHandler(CustomHandler)

而不是

    Application.Context.Handler = CustomHandler