For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > March 2006 > How to hook httpmodule and page event together?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to hook httpmodule and page event together?
walter

2006-03-30, 7:04 pm

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

Bruno Piovan

2006-03-30, 7:04 pm

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




"walter" <wwu@morneausobeco.com> wrote in message
news:8FC436D1-1BD2-42B0-86CD-2DF69B681CF7@microsoft.com...
> 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
>



walter

2006-03-31, 7:03 pm

Hi Bruno,you answer is awesome. Thanks

"Bruno Piovan" wrote:

> 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
>
>
>
>
> "walter" <wwu@morneausobeco.com> wrote in message
> news:8FC436D1-1BD2-42B0-86CD-2DF69B681CF7@microsoft.com...
>
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com