Checking for unitialized Session key

  • Thread starter Thread starter Michel Salim
  • Start date Start date
M

Michel Salim

Hello,

In my application I am trying to check if a HttpContext.Session key is
set, and if not, retrieve its value by making a function call.

The code excerpt as it stands:

Dim userEntry As LdapEntry =
HttpContext.Current.Session("userEntry")
If userEntry Is Nothing Then
Dim UserAuthentication As New UserAuthentication
userEntry =
UserAuthentication.GetDetails(Page.User.Identity.Name)
End If

(LdapEntry comes from Novell's LDAP library for .NET, and
UserAuthentication is a custom class)

The problem is that userEntry does not contain a null object
(Nothing), it is simply uninitialized, and I get a runtime error to
that effect.

Is there a way to deal with this properly, or should I just attempt to
use userEntry within a try/catch block?

Thanks in advance,

- Michel
 
Check out the Novell doc. IMO, it's likely an uninitalized LdapEntry can be
checked (username empty or something similar).

Patrice
 
Hello,

In my application I am trying to check if a HttpContext.Session key is
set, and if not, retrieve its value by making a function call.
Thanks for the replies. I did try checking if the Session key 'is
nothing', which failed, but it turns out that was because, as Patrice
suggested, the mistake I made was in the function that interfaced with
the Novell LDAP library.

- Michel
 
Back
Top