Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if ASP.NET Sessions are enabled

What is the best way to do a boolean test in C# to determine if ASP.NET sessions are enabled? I don't want to use a try-catch block and Sessions != null throws an Exception.

Regards.

like image 621
Keith Adler Avatar asked Jan 23 '23 06:01

Keith Adler


1 Answers

You will not get an exception if you use HttpContext.Current:

if(HttpContext.Current.Session != null)
{
    // Session!
}
like image 71
John Rasch Avatar answered Jan 25 '23 20:01

John Rasch