The Global.ASAX File
page 4 of 4
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 32296/ 60

HTTPModules

HTTPModules

If you've been reading in the Related Articles you will know that HTTPModules can expose events and these events can be handled in global.asax.

Here I'll just give you a quick module and handler, but you will be able to see the advantages of it.

 

Here is our sample HTTPModule -

Imports System
Imports
System.Web

Public Class QuickModule : Implements IHttpModule

Public Event tester As EventHandler

Public Sub Dispose() Implements IHttpModule.Dispose
End
Sub

Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init
AddHandler
application.BeginRequest, AddressOf
OnBeginRequest
End
Sub

Public Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent
tester(Me
, EventArgs.Empty)
End
Sub

End Class

The bit from the web.config file -

<httpModules>
<
add name="QuickModule" type="HttpModHan.QuickModule, HttpModHan" />
</
httpModules
>

As well as a bit from the global.asax file -

Sub QuickModule_tester(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("EVENT HANDLER TRIGGERED!!!")

End
Sub

I don't think that there is any need for a demo here because the result is obvious. You can see that all we did to handle it was to put -

ModuleName_EventName(sender as object, e as EventArgs)

And ModuleName is the name that you defined in web.config.

Summary

Well, that's Global.asax for you. As you can see, it's a hell of a lot more powerful now than in Classic ASP and the fact that you can now develop your own events to handle in there just makes it all that more important and useful to your application. Check the Related Articles for more information on HTTPModules if you haven't heard of them before or want more information on them.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-03-02 12:00:23 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search