Imports System.IO
Public Class DriverMaster2
    Inherits System.Web.UI.MasterPage

    Property CurrentDriver As Logic.DriverAccount
    Property CurrentPage As String

    Property CurrentClient As String

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.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()

            Dim driverId = SessionVars.DriverId(Session)
            If driverId > 0 Then
                CurrentDriver = New Logic.DriverAccount(driverId)
            Else
                If String.IsNullOrEmpty(SessionVars.PostLoginUrl(Session)) Then
                    SessionVars.PostLoginUrl(Session) = Request.Url.ToString()
                End If
                Response.Redirect("/Driver2/Login2.aspx", False)
            End If

        Catch ex As Exception
            Dim errorId = Logic.Error.Log(ex)
            Response.Redirect("/Error.aspx?id=" & errorId, False)
        End Try
    End Sub
    Public Function GetClient() As String
        GetClient = CurrentClient
    End Function


    Private Sub btnDashboard_Click() Handles btnDashboard.Click
        Response.Redirect("/Driver2/Dashboard2.aspx", False)
    End Sub

    Private Sub btnLogout_Click() Handles btnLogout.Click
        Response.Redirect("/Driver2/Logout2.aspx", False)
    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

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Try
        '    If My.Settings.httpsOnly Then
        '        _SecurePage()
        '    End If

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

        '    Dim driverId = SessionVars.DriverId(Session)
        '    If driverId > 0 Then
        '        CurrentDriver = New Logic.DriverAccount(driverId)
        '    Else
        '        If String.IsNullOrEmpty(SessionVars.PostLoginUrl(Session)) Then
        '            SessionVars.PostLoginUrl(Session) = Request.Url.ToString()
        '        End If
        '        'Response.Redirect("/Driver2/Login.aspx", False)
        '    End If

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