Get the current logged in user id


In order to get the Id of the current logged in user using ASP.NET Identity, we use the GetUserId method.


The GetUserId method returns the user id for the current HTTP request.

string userId = User.Identity.GetUserId();


In order to use the GetUserId method, you have to include the following namespace :

using Microsoft.AspNet.Identity;