Click to See Complete Forum and Search --> : ASP.Net storing objects in session state


timjs
04-30-2007, 03:43 AM
Hi,

How do I check if an ASP.net session contains a particular variable or not? I want to do something like this.


if Session("user") <> "" Then
'... do something here...
End if

I do not know the type of the data that is stored in Session("user"). I just want to know if anything has been assigned to it.

The above causes an error:

Overload resolution failed because no Public '<>' can be called with these arguments:
'Public Shared Operator <>(a As String, b As String) As Boolean':
Argument matching parameter 'a' cannot convert from 'SchedulerUser' to 'String'.

I hope someone can help!

Cstick
04-30-2007, 10:28 PM
If Session("user") IsNot Nothing Then
'Do something.
End If

birre
05-04-2007, 05:21 AM
IF not Session("user") = String.Empty THEN
do something
END IF


Even if the Session isn't yet created, it'll always throw a String.Empty