title: How to store and retrieve objects in Session state in ASP.NET Core 2.x?
body: <p><strong><em>How would I add EmployeeId and DesignationId to an object and then retrieve it from Session state afterward?</em></strong></p>
  
  <p><strong>Here is my login controller Code:</strong></p>
  
  <pre><code>DataTable dt = sql.GetDataTable("select * from EmpDetails where EmailId = '" + EmailId + "'");
  string strempstatus = dt.Rows[0]["Status"].ToString();
  string EmpStatus = strempstatus.TrimEnd();
  
  //Models.UserDetails detail = new Models.UserDetails();
  
  if (EmpStatus == "Verified")
  {
      //i want to create object which store below two variable value
      string EmployeeId = dt.Rows[0]["Id"].ToString();
      string DesignationId = dt.Rows[0]["D_Id"].ToString();
  
      //I want to stored object in below session
      HttpContext.Session.SetString("EmployeeData", EmployeeId);
  
      HttpContext.Session.SetInt32("EmployeeID", Convert.ToInt32(EmployeeId));
      //For Destroy Session
      //HttpContext.Session.Remove("EmployeeID");
  
      Int32? Saved = HttpContext.Session.GetInt32("EmployeeID");
  
      if (DesignationId == "1")
      {
          return RedirectToAction("Index", "AdminDashboard");
      }
      else
      {
          return RedirectToAction("Index", "UserDashboard");
      }
  }
  </code></pre>