Groups > Asp .Net > HttpHandlers and HttpModules > Re: httpmodule for redirecting page




httpmodule for redirecting page

httpmodule for redirecting page
Fri, 28 Mar 2008 12:47:04 +000
Hi, i got this code from microsoft msdn
http://msdn2.microsoft.com/en-us/library/ms227673(VS.80).aspx
Here is the code :
I understand that, if i run this program, i will see "HelloWorldModule:
Beginning of Request " begnning of hte page.

Now i will come to my original question : 
I am trying to Edit this code so that, it can redirect " Certain page"
like page1 and page3 to https . 
i understand that i wil have to write this redirection code here :

Private Sub Application_BeginRequest(ByVal source As Object, _
            ByVal e As EventArgs)
but , Question 1. what code shall i write
??-----------------------------------------------------

Question2 - how will i  sent request to this class so that it only redirect 
page1 and page3 to https , other pages in my domain would be http.

Please advise me. i need the solution.

Here is the Code:

ImportsMicrosoft.VisualBasic
 
PublicClassHelloWorldModule
    ImplementsIHttpModule
 
    PublicReadOnlyPropertyModuleName()As[String]
        Get
            Return"HelloWorldModule"
        EndGet
    EndProperty
 
    ' In the Init function, register for HttpApplication 
    ' events by adding your handlers.
    PublicSubInit(ByVal application AsHttpApplication) _
            ImplementsIHttpModule.Init
        AddHandler application.BeginRequest, _
            AddressOfMe.Application_BeginRequest
        AddHandler application.EndRequest, _
            AddressOfMe.Application_EndRequest
    EndSub
 
    PrivateSubApplication_BeginRequest(ByVal source AsObject, _
            ByVal e AsEventArgs)
    ' Create HttpApplication and HttpContext objects to access
    ' request and response properties.
        Dim application AsHttpApplication=CType(source, _
            HttpApplication)
        Dim context AsHttpContext= application.Context
        context.Response.Write _
           ("<h1><font color=red>HelloWorldModule: "&
_
                "Beginning of
Request</font></h1><hr>")
    EndSub
 
    PrivateSubApplication_EndRequest(ByVal source AsObject, _
            ByVal e AsEventArgs)
        Dim application AsHttpApplication=CType(source, _
            HttpApplication)
        Dim context AsHttpContext= application.Context
        context.Response.Write _
            ("<hr><h1><font color=red>HelloWorldModule:
"& _
                "End of Request</font></h1>")
    EndSub
 
    PublicSubDispose()ImplementsIHttpModule.Dispose
    EndSub
EndClass
Post Reply
Re: httpmodule for redirecting page
Wed, 2 Apr 2008 10:26:18 +0000
Hi fosiul,

It is possible to compare the Url, when the URL is page1 and page3, do the
redirection. However this can be done without Http Modules, you can redirect in
the code of page1 and page3.
Post Reply
about | contact