Back to: ASP.NET MVC Tutorial For Beginners and Professionals
How to Get the Current Logged-in User Id in ASP.NET Identity
Once the user logs in, then in order to get the Id of the currently logged-in user in ASP.NET Identity, we need to use the GetUserId method.
GetUserId
The GetUserId method returns the user id for the current HTTP request. The syntax to use the GetUserId() method is as follows:
string userId = User.Identity.GetUserId();
Namespace: In order to use the GetUserId method, you have to include the following namespace:
using Microsoft.AspNet.Identity;
In the next article, I am going to discuss How to Logout a User in ASP.NET Identity. Here, in this article, I try to explain How to Get the Current Logged in User Id in ASP.NET Identity. I hope you enjoy this article.
You should have told which file we can add the code. Now Im really confused