UserID from User Table

Vote:
 

Hello, all I am trying to make a simple request to retrieve the UserID from the Users Table after they have registered the user. 

I have read that there are calls on Commerce Server to get this info:

PrincipalInfo.CurrentPrincipal.GetContactId()

For user name and email:

var customerContact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); 

However I cannot find anything on the CMS side that will do the same thing. Any help would be appreciated. 

#202508
Mar 27, 2019 20:10
Vote:
 
#202509
Mar 27, 2019 21:20
Vote:
 

Hi Greg

If you are using ASP.Net Identity for authentication, you can get the UserId of a logged-in user like this.

// Inside a controller or view.
string userId = User.Identity.GetUserId();

// Anywhere else.
string userId = PrincipalInfo.CurrentPrincipal.Identity.GetUserId();

Mind you, this method reads the UserId from authentication cookie, not directly from database.

#202625
Mar 28, 2019 6:36
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.