Checking for a session variable... returns (Object reference not set to an instance of an object.)

Posted by Chocol8 on Stack Overflow See other posts from Stack Overflow or by Chocol8
Published on 2011-01-12T19:45:59Z Indexed on 2011/01/12 19:53 UTC
Read the original article Hit count: 122

In the Session_Start i have

 Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
  Session("login") = False
 End Sub

and in a custom .aspx page i included the following...

 Public ReadOnly Property GetLoginState() As Boolean
        Get
            If Current.Session("login") Is Nothing Then
                Current.Session("login") = False
            End If
            Return Current.Session("login")
        End Get
 End Property

Why i am getting error the error

Object reference not set to an instance of an object.

at line

If Current.Session("login") Is Nothing Then

while checking for the login state as follows?

   If GetLogin = False Then
    'Do something
   End if

I mean i have already created the instance on the Session_Start... Haven't i? What am i doing wrong here?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net