Some of my pages in the app I am developing inherit from a BasePage class I
have created. I have done plenty of these in the past and they work fine.
Now, however, I have an additional requirement.
In my BasePage class I need to check the user's browser for a particular
cookie, and if certain conditions aren't met, redirect the user to another
page. You can see the code for my BasePage class below. The problem lies in
the LoggedIn function. I am getting the error
"System.NullRef erenceException : Object reference not set to an instance of
an object" on the first line of that function. Any ideas?
Public Class SecureAdminBase Page
Inherits System.Web.UI.P age
Protected Overrides Sub OnInit(ByVal e As System.EventArg s)
Me.Controls.Add At(0,
LoadControl("/UserControls/SecureAdminHead er.ascx"))
MyBase.OnInit(e )
Me.Controls.Add (LoadControl("/UserControls/SecureAdminFoot er.ascx"))
End Sub
Private Function LoggedIn()
If Not MyBase.Request. Cookies("TSRAdm in").Value.ToSt ring = "TRUE" _
Or Not IsNumeric(MyBas e.Request.Cooki es("au_id").Val ue.ToString)
Then
Return False
Else
Return True
End If
End Function
Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)
MyBase.OnLoad(e )
'Be sure user is logged in
If Not LoggedIn() Then
Response.Redire ct("/admin/login/")
End If
End Sub
End Class