views:

32

answers:

0

I have the following code:

if (null != HttpContext.Current && null != HttpContext.Current.Session
    && null != HttpContext.Current.Session["key"]) {
        // some cool magic
}

which sometimes throws ArgumentNullException in HttpContext.Current.Session["key"] (HttpContext.Current and HttpContext.Current.Session are not null).

How to prevent exception to be thrown?

Upd.

  • HttpContext.Current.Session.Count > 0
  • Session state mode is SQLServer