Imports Microsoft.VisualBasic
Imports System.Xml

Public Class SecureHandler
    Implements IHttpHandler

    Private Const visitorsFolder As String = "/visitors/"
    Private Const membersFolder As String = "/members/"
    Private Const orderFolder As String = "/Order/"
    Private Const accountFolder As String = "/Account/"
    Private Const CBAccountFolder As String = "/CBAccount/"
    Private Const msFolder As String = "/ms/"
    Private Const CBmsFolder As String = "/CBms/"
    ' Private Const externalAffliateFolder As String = "/externalaffiliate/"
    ' Private Const affliateFolder As String = "/Affliate/"
    Private Const httpsPort As String = "https:"
    Private Const httpPort As String = "http:"

    Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
        Try
            If Not context Is Nothing Then
                Dim currentURL As String = context.Request.Url.ToString()
                '######################################################################################
                'THIS CONDITION ALLOWS THE UI TO BE RAN ON THE LOCALHOST FOR 
                'DEVELOPMENT PURPOSES, EVEN IN SECURED (HTTPS) AREAS. WHEN 
                'RUNNING ON LOCALHOST, WE SHOULD BE USING HTTPS NORMALLY.
                'PROB WOULDN'T BE AN ISSUE IF YOU ARE DEVELOPING ON A SERVER 2003 RATHER THAN XP PRO.
                '######################################################################################
                Dim strMachineName As String = Environment.MachineName.ToUpper()



                Select Case strMachineName.ToUpper()
                    Case "KSTLINTC64V6855" 'JOHN CORTRIGHT
                    Case "KSTLINTC20V5109" ' Jude Naes
                    Case "KSTLUSRS64V09YS" ' Jim Gilbert
                    Case Else
                        Select Case True
                            Case currentURL.ToUpper().Contains("HTTP://KSTLMWEB65:82") 'CHARTER.COM CL DEV BOX
                            Case Else
                                currentURL = currentURL.Replace(httpPort, httpsPort)
                        End Select
                End Select

                'currentURL = currentURL.ToLower.Replace(externalAffliateFolder, affliateFolder)
                currentURL = currentURL.ToLower.Replace(visitorsFolder, orderFolder)
                currentURL = currentURL.ToLower.Replace(membersFolder, accountFolder)

                currentURL = currentURL.ToLower.Replace(msFolder, accountFolder)

                currentURL = currentURL.ToLower.Replace(CBmsFolder, CBAccountFolder)

                HttpContext.Current.Response.Redirect(currentURL, True)


                'HttpContext.Current.Response.Status = "301 Moved Permanently"
                'HttpContext.Current.Response.AddHeader("Location", currentURL)
                'HttpContext.Current.Response.End()





            End If
        Catch ex As Exception

        End Try
    End Sub

End Class
