Get the current logged in user id

Introduction


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

GetUserId


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

string userId = User.Identity.GetUserId();

Namespace


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

using Microsoft.AspNet.Identity;