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.
You will not get an exception if you use HttpContext.Current
:
if(HttpContext.Current.Session != null)
{
// Session!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With