How to hook httpmodule and page event together?

G

Guest

Hi there , for sure httpmodule can be hooked up with HttpApplication event.
But I'm wondering if it's poissible to trigger a httpModule in the page event
,like Page.Init().

Since request handler will be different among http/aspx, I hardly see it's
possible. But may be someone knows. Reason I want to do this is because I
like the plugin model provided by asp.net framework, but this time is just
for page. If I can hook httpmodule and page event together, then I can make
the page become plugable.

Appreciate any inspiriting thought.

Walter
 
B

Bruno Piovan

Walter,
take a look at this code I wrote...
it will handle the PageInit event for all pages.....

I hope it helps..

Bruno


Public Class MyModule

Implements IHttpModule

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

End Sub

Public Sub Init(ByVal context As System.Web.HttpApplication) Implements
System.Web.IHttpModule.Init

AddHandler context.PreRequestHandlerExecute, AddressOf
PreRequestHandlerExecute

End Sub

Sub PreRequestHandlerExecute(ByVal sender As Object, ByVal e As
System.EventArgs)

AddHandler CType(CType(sender, HttpApplication).Context.CurrentHandler,
Page).Init, AddressOf PageInit

End Sub

Private Sub PageInit(ByVal sender As Object, ByVal e As System.EventArgs)

Dim p As Page = CType(sender, Page)

p.Response.Write("Hello")

End Sub

End Class
 
G

Guest

Hi Bruno,you answer is awesome. Thanks

Bruno Piovan said:
Walter,
take a look at this code I wrote...
it will handle the PageInit event for all pages.....

I hope it helps..

Bruno


Public Class MyModule

Implements IHttpModule

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

End Sub

Public Sub Init(ByVal context As System.Web.HttpApplication) Implements
System.Web.IHttpModule.Init

AddHandler context.PreRequestHandlerExecute, AddressOf
PreRequestHandlerExecute

End Sub

Sub PreRequestHandlerExecute(ByVal sender As Object, ByVal e As
System.EventArgs)

AddHandler CType(CType(sender, HttpApplication).Context.CurrentHandler,
Page).Init, AddressOf PageInit

End Sub

Private Sub PageInit(ByVal sender As Object, ByVal e As System.EventArgs)

Dim p As Page = CType(sender, Page)

p.Response.Write("Hello")

End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top