title: ASP.NET Core Identity - get current user
body: <p>To get the currently logged in user in MVC5, all we had to do was:</p>
  
  <pre><code>using Microsoft.AspNet.Identity;
  [Authorize]
  public IHttpActionResult DoSomething() {
      string currentUserId = User.Identity.GetUserId();
  }
  </code></pre>
  
  <p>Now, with ASP.NET Core I thought this should work, but it throws an error.</p>
  
  <pre><code>using Microsoft.AspNetCore.Identity;
  using Microsoft.AspNetCore.Http;
  
  private readonly UserManager&lt;ApplicationUser&gt; _userManager;
  [HttpPost]
  [Authorize]
  public async Task&lt;IActionResult&gt; StartSession() {
      var curUser = await _userManager.GetUserAsync(HttpContext.User);
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT:</strong> Gerardo's response is on track but to get the actual "Id" of the user, this seems to work:</p>
  
  <pre><code>ClaimsPrincipal currentUser = this.User;
  var currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
  </code></pre>