Imports System.IO
Imports System.Threading

Public Class SiteMaster
    Inherits System.Web.UI.MasterPage

    Property CurrentPage As String

    Private Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
        Try
            If My.Settings.httpsOnly Then
                _SecurePage()
            End If

            Dim uri As New Uri(Request.Url.AbsoluteUri)
            CurrentPage = Path.GetFileName(uri.LocalPath).ToLower()

        Catch ex As ThreadAbortException
            ' nop
        Catch ex As Exception
            Dim errorId = Logic.Error.Log(ex)
            Response.Redirect("/Error.aspx?id=" & errorId)
        End Try
    End Sub

    ' Make us use https
    Private Sub _SecurePage()
        Dim ServerName As String = Server.UrlEncode(Request.ServerVariables.Item("SERVER_NAME"))
        Dim FilePath As String = Request.Url.PathAndQuery
        If Not Request.IsSecureConnection Then
            Response.Redirect("https://" & ServerName & FilePath)
        End If
    End Sub

End Class