Imports Microsoft.VisualBasic
Imports System.Collections.Generic

Public Class SEOPage
    Inherits Page

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ''############################################################
        'MODIFICATION   ROD COPELAND    7/18/2008   ISSUE ID 2374
        'ADDING THE SEARCH ENGINE OPTIMIZATION USAGE INDICATOR
        '############################################################
        Try
            If Not (HttpContext.Current.Application("SEARCH_ENGINE_OPTIMIZATION_URL_COLLECTION") Is Nothing) Then
                If HttpContext.Current.Application("SEARCH_ENGINE_OPTIMIZATION_URL_COLLECTION").ToString() <> "placeholdervalue" Then

                    Dim SEOCollection As New Dictionary(Of String, String)
                    SEOCollection = HttpContext.Current.Application("SEARCH_ENGINE_OPTIMIZATION_URL_COLLECTION")
                    If Not (SEOCollection Is Nothing) Then

                        '##############################################################
                        'SEND THE USER TO THE SEARCH ENGINE OPTIMIZED URL INDICATED.
                        '##############################################################
                        Dim lURLToCompare As String = HttpContext.Current.Request.Url.PathAndQuery.ToString().ToLower().Replace("/ui/", "/")
                        Dim dotComIndex As Integer
                        Dim relativePath As String = ""
                        If SEOCollection.ContainsKey(lURLToCompare) Then

                            If SEOCollection(lURLToCompare).Contains(".com") Then
                                dotComIndex = SEOCollection(lURLToCompare).IndexOf(".com")
                                relativePath = "~" & SEOCollection(lURLToCompare).Substring(dotComIndex + 4)
                            Else
                                relativePath = "~" & SEOCollection(lURLToCompare)
                            End If
                            '#################################################################################################
                            'NORMAL REDIRECTS FOR VISITORS/SUPPORT.ASPX GOING TO CUSTOMERS/SUPPORT.ASPX.
                            'WHEN LOADING THE URLS IN THE REDIRECT TABLE, BE SURE TO USE THE FINAL DESTINATION URL 
                            '(/visitors/support.aspx) RATHER THAN THE REDIRECT URL (/customers/support.aspx). 
                            'THIS SERVER TRANSFER WILL BE TRYING TO VALIDATE THE FILE ACTUALLY EXISTS 
                            'IN THE DESTINATION, IN THE CASE OF THE NORMAL FOLDER REDIRECT AS A DESTINATION, IT WOULDN'T 
                            'EXITS AND AN ERROR WOULD BE GENERATED.
                            '#################################################################################################
                            'ANOTHER NOTABLE POINT IS THAT WHEN YOU DO A TRANSFER TO A PAGE AND LOAD IN A SEO PATH THAT IS 
                            'DEEPER THAN ONE FOLDER, IT WILL TYPICALLY BREAK THE STYLESHEET REFFERENCE SINCE IT'S CMS MANAGED 
                            'FOR ALL THE PAGES MOSTLY AND IS EXPECTING TO BE LOADED FROM ONE FOLDER DEEP.  FYI.
                            '#################################################################################################
                            HttpContext.Current.Server.Transfer(relativePath)
                        End If

                    End If
                End If
            End If
        Catch ex As Exception
            '##########################################################################################
            'DONT FAIL THE WHOLE PAGE JUST BECAUSE SEARCH ENGINE OPTIMIZATION IS CAUSING AN EXCEPTION.
            '##########################################################################################
        End Try


    End Sub

End Class
