title: Get UserID of logged-in user in Asp.Net MVC 5
body: <p>I'm relatively new to ASP.Net MVC and try to use the built-in user login functionality now. I'm able to register an user in the registration view. If I try to login with the created user this also works. I'm redirected to the master page.</p>
  
  <p>But I'm not able to get the UserID of the current user. I tried my code in the HomeController and in the AccountController, but both didn't work. The statement in the first line returns always null.</p>
  
  <pre><code>var userID = User.Identity.GetUserId();
  
  if (!string.IsNullOrEmpty(userID))
  {
      var manager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(ApplicationDbContext.Create()));
      var currentUser = manager.FindById(User.Identity.GetUserId());
  }
  </code></pre>
  
  <p>Do I have to to something else before getting the UserID?</p>