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.NullReferenceException: Object reference not set to an instance of
an object" on the first line of that function. Any ideas?
Public Class SecureAdminBasePage
Inherits System.Web.UI.Page
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
Me.Controls.AddAt(0,
LoadControl("/UserControls/SecureAdminHeader.ascx"))
MyBase.OnInit(e)
Me.Controls.Add(LoadControl("/UserControls/SecureAdminFooter.ascx"))
End Sub
Private Function LoggedIn()
If Not MyBase.Request.Cookies("TSRAdmin").Value.ToString = "TRUE" _
Or Not IsNumeric(MyBase.Request.Cookies("au_id").Value.To String)
Then
Return False
Else
Return True
End If
End Function
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
'Be sure user is logged in
If Not LoggedIn() Then
Response.Redirect("/admin/login/")
End If
End Sub
End Class