ASP.Net中自定义Http处理及应用之HttpModule篇
我参考《ASP.Net中自定义Http处理及应用之HttpModule篇》一文:
http://www.xxy8.com/v2/2003-8/2003826192506.htm
写的代码:
web.config
MyHttpModule.vb
http://www.xxy8.com/v2/2003-8/2003826192506.htm
写的代码:
web.config
<configuration>
<system.web>
<httpModules>
<add name="test" type="test.MyHttpModule, test" />
</httpModules>
</system.web>
</configuration>
<system.web>
<httpModules>
<add name="test" type="test.MyHttpModule, test" />
</httpModules>
</system.web>
</configuration>
MyHttpModule.vb
Public Class MyHttpModule
Implements IHttpModule
Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.init
AddHandler application.BeginRequest, AddressOf Application_BeginRequest
AddHandler application.EndRequest, AddressOf Application_EndRequest
End Sub
Private Sub Application_BeginRequest(ByVal source As Object, ByVal e As EventArgs)
Dim Application As HttpApplication = CType(source, HttpApplication)
Dim Response As HttpResponse = Application.Context.Response
Response.Write("<h1>Beginning of Request</h1><hr>")
End Sub
Private Sub Application_EndRequest(ByVal source As Object, ByVal e As EventArgs)
Dim application As HttpApplication = CType(source, HttpApplication)
Dim Response As HttpResponse = application.Context.Response
Response.Write("<h1>End of Request</h1><hr>")
End Sub
Public Sub Dispose() Implements IHttpModule.Dispose
End Sub
End Class
Implements IHttpModule
Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.init
AddHandler application.BeginRequest, AddressOf Application_BeginRequest
AddHandler application.EndRequest, AddressOf Application_EndRequest
End Sub
Private Sub Application_BeginRequest(ByVal source As Object, ByVal e As EventArgs)
Dim Application As HttpApplication = CType(source, HttpApplication)
Dim Response As HttpResponse = Application.Context.Response
Response.Write("<h1>Beginning of Request</h1><hr>")
End Sub
Private Sub Application_EndRequest(ByVal source As Object, ByVal e As EventArgs)
Dim application As HttpApplication = CType(source, HttpApplication)
Dim Response As HttpResponse = application.Context.Response
Response.Write("<h1>End of Request</h1><hr>")
End Sub
Public Sub Dispose() Implements IHttpModule.Dispose
End Sub
End Class