Introducing HTTPModules
page 3 of 4
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 25362/ 34

Creating an HTTPModule
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.


View Entire Article

User Comments

Title: thak you....   
Name: veni.R.L
Date: 2005-05-18 1:27:46 AM
Comment:
thank you....

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 3:29:55 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search