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.
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:
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.
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.