How to determine Session alive?

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi, I write asp.net via c#.
How should I know the client's session alive?

1. if ( Session["uid"].Equals ( null ) )
2. if ( Convert.IsDBNull(Session["uid"]) )
3. if ( Session.Contents.Count == 0 )

Thanks for your kind advice, David.
 
David said:
Hi, I write asp.net via c#.
How should I know the client's session alive?

1. if ( Session["uid"].Equals ( null ) )

this would work
2. if ( Convert.IsDBNull(Session["uid"]) )

this would NOT work: "DbNull" is a special signal that a *database field*
contains a null-value, and null is not equal to DbNull(.Value)
3. if ( Session.Contents.Count == 0 )

would also work, although you can leave out the "Contents",
"Session.Count" is enough. MSDN quote:
The Contents property is provided for compatibility with earlier versions of ASP.
 
hi david,


well a session will always be alive , each time a request is send to the
server a new session is created if needed, the only place where you can know
that a session is gone is in the session_end handler.

what yoiu can do is check if a session is new or old, or if the session
passed certain milestone, you know if it's a new session in the
session_start handler.
You can always chgeck for "milestones" or states checking variables in
session as you do ni your first variant.


cheers,
 
Back
Top