title: How to check if session value is null or session key does not exist in asp.net mvc - 5
body: <p>I have one ASP.Net MVC - 5 application and I want to check if the session value is null before accessing it. But I am not able to do so.</p>
  
  <pre><code>//Set
  System.Web.HttpContext.Current.Session["TenantSessionId"] = user.SessionID;
  // Access
  int TenantSessionId = (int)System.Web.HttpContext.Current.Session["TenantSessionId"];
  </code></pre>
  
  <p>I tried many solutions from SO</p>
  
  <p>Attempt</p>
  
  <pre><code>if (!string.IsNullOrEmpty(Session["TenantSessionId"] as string))
   {
                  //The code
   }
  </code></pre>
  
  <p>Kindly guide me.</p>
  
  <p><strong>Error: NULL Reference</strong></p>