Get the current logged in user id (2024)

Table of Contents
Introduction GetUserId Namespace

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;

Get the current logged in user id (2024)
Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6386

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.