title: ASP.NET MVC - Login Success, but userId returns null
body: <p>I'm using the basic mvc-5 login method and just trying to access the userid on success</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
  {
      if (!ModelState.IsValid)
      {
          return View(model);
      }
  
      // This doesn't count login failures towards account lockout
      // To enable password failures to trigger account lockout, change to shouldLockout: true
      var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
      switch (result)
      {
          case SignInStatus.Success:
              string userId = User.Identity.GetUserId();
              returnUrl = CheckUserRoleAndRedirect();
              return RedirectToLocal(returnUrl);
          case SignInStatus.LockedOut:
              return View("Lockout");
          case SignInStatus.RequiresVerification:
              return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
          case SignInStatus.Failure:
          default:
              ModelState.AddModelError("", "Invalid login attempt.");
              return View(model);
      }
  }
  </code></pre>
  
  <p>Here <code>string userId = User.Identity.GetUserId();</code> userId return null for the 1st time but next time it works fine</p>