Creation of an HTTPModule
Below is just a simple HTTPModule -
Imports System
Imports System.Web
Imports System.Diagnostics
Public
Class
SampleModule : Implements
IHttpModule
Public
Sub Dispose()
Implements
IHttpModule.Dispose
End
Sub
Public
Sub Init(ByVal
application As
HttpApplication) Implements
IHttpModule.Init
AddHandler application.BeginRequest,
AddressOf
Me.OnBeginRequest
End
Sub
Public
Sub
OnBeginRequest(ByVal
sender As
Object,
ByVal e
As
EventArgs)
Dim app As
HttpApplication = CType(sender,
HttpApplication)
Dim browscap
As HttpBrowserCapabilities
= app.Request.Browser
If browscap.Browser = "Netscape"
Then
'w00t
ElseIf
browscap.Browser = "IE"
Then
'EEK!
Else
'wha?
End
If
End
Sub
End
Class |
As you can see, this class implements all of
the required methods, it also adds a handler for one of it's events. The event
handling is usually the way that you time your events correctly as shoving it in
the Init method isn't the most effective way.
Currently it doesn't do anything but check the
browser and print the name of the browser to the screen.
The next thing you have to do is add it to the
web.config of the application like -
<httpModule>
<add
name="SampleModle"
type="HttpModHan.SampleModule,
HttpModHan"
/>
</httpModule> |
<add name="A Name" type="Class,
Assembly" />
It should look like -
When running.