IHttpModule and Master Page

Geppos1975

New member
Joined
Mar 2, 2009
Messages
1
Programming Experience
1-3
I'd like to change my master page dinamically through pages.
I want to use Ihttpmdule so i don't need to add preinit event in all pages.

I write this code in VB NET:

Public Class ProvaHttp
Implements IHttpModule

Public Sub New()
' Costruttore
End Sub

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

Protected Sub PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
Dim CurrentContext As HttpContext = HttpContext.Current
If (Not TypeOf CurrentContext.Handler Is Page) Then Return
Dim myPage As Page = CurrentContext.Handler

If myPage.MasterPageFile = Nothing Then
Else
myPage.MasterPageFile = CurrentContext.Session.Item("MasterPage")
End If
myPage.Theme = CurrentContext.Session.Item("Tema")
End Sub
End Class


I managed to change themes but not master page.

Can someone help me??

Thanks in advance.

Giuseppe
 
Back
Top