title: how to access session variable in ASP.Net MVC
body: <p>I have a ASP.Net MVC 5 web application and I want to set a variable in the session so that I can access it later. As I am a beginner I don't know how to achieve it. Below is what I have tried</p>
  
  <pre><code>clsUser user = mdlUser.GetUserForSession();
  System.Web.HttpContext.Current.Session["MyValue"] = user.SessionID; // user.SessionID is an integer
  int x =  System.Web.HttpContext.Current.Session["MyValue"] as int; // Access
  </code></pre>
  
  <p>But I get error as Error as</p>
  
  <blockquote>
    <p>The as operator must be used with a reference type or nullable type ('int' is a non-nullable value type)</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/735133/asp-net-mvc-how-to-access-session-data-in-places-other-than-controller-and-vie">SO LINK REFERRED</a></p>