What is the best way to check for the existence of a session variable in ASP.NET C#?
I like to use String.IsNullOrEmpty() works for strings and wonder
String.IsNullOrEmpty()
It may make things more elegant to wrap it in a property.
string MySessionVar { get{ return Session["MySessionVar"] ?? String.Empty; } set{ Session["MySessionVar"] = value; } }
then you can treat it as a string.
if( String.IsNullOrEmpty( MySessionVar ) ) { // do something }