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 wondered if there was a similar method for Session
. Currently the only way I know of is:
var session;
if (Session["variable"] != null)
{
session = Session["variable"].ToString();
}
else
{
session = "set this";
Session["variable"] = session;
}