title: how to use session with HttpContext.Current at null
body: <p>I'm trying to use session but when I call the SetSession method, I see that HttpContext.Current is null, so I get MinValue (from gettor because session property is null) how to fix this issue? because of that, everytime I'm trying to get session variables, it doesn't work, indeed =D it looks I forgot something but...</p>
  
  <p>From the controller I call the SessionManager when user is connecting:</p>
  
  <pre><code>var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
              switch (result)
              {
                  case SignInStatus.Success:
                      {
                          var identityUser = UserManager.FindByEmail(model.Email);
  
                          if (identityUser.Matricule.IsNotNull() &amp;&amp; !identityUser.Matricule.HasValue)
                          {
                              SetAlert("Error");
                          }
                          else
                          {
                              SessionManager.matricule = identityUser.Matricule.Value;
  
                              var user = BL.PersonnelBL.GetAll(SessionManager.matricule); 
                              SessionManager.firstName = user.prenom;
                              SessionManager.lastName = user.nom;
                              SessionManager.chainId = user.chaine.chaine;
                              SessionManager.secteurId = user.chaine.secteur.Id;
                              SessionManager.serviceId = user.chaine.service.Id;
                              SessionManager.isAuditor = user.auditTarget.IsNull() ? false : true;
                          }
  
                          // Redirect to local
                          return RedirectToLocal(returnUrl);
                      }
                  case SignInStatus.LockedOut:
                      return View("Lockout");
                  case SignInStatus.RequiresVerification:
                      return RedirectToAction("SendCode", new { ReturnUrl = returnUrl });
                  case SignInStatus.Failure:
                  default:
                      ModelState.AddModelError("", "Invalid login attempt.");
                      return View(model);
              }
  </code></pre>
  
  <p>Session manager:</p>
  
  <pre><code>public class SessionManager
      {
      public static int matricule
              {
                  get
                  {
                      object property = GetSession("MATRICULE");
                      if (property != null)
                      {
                          return Convert.ToInt32(property);
                      }
                      return int.MinValue;
                  }
                  set 
                  {
                      SetSession("MATRICULE", value);
                  }
              }
  }
  private static bool SetSession(string key, object value)
          {
              if (HttpContext.Current != null &amp;&amp; HttpContext.Current.Session != null)
              {
                  HttpContext.Current.Session[key] = value;
                  return true;
              }
              return false;
          }
  </code></pre>
  
  <p>Inside Web.Config:</p>
  
  <pre><code>&lt;system.web&gt;
  ...
  &lt;sessionState mode="InProc" timeout="45" /&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>Thanks in advance</p>