previously I was using AspNet Microsoft.AspNet.Identity; to get the current user ID accessing api with following code
string userId = User.Identity.GetUserId();
Now I migrated whole project from AspNet to AspNetCore but how can I get current user ID accessing api?
Tried following code which returned username
var userName = User.FindFirstValue(ClaimTypes.Name);
I googled and found I have to use the following code to get userID,
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
but it returned with 204, No Content
John DavisPosted Jun 9, 2022, 3:02 PM
John DavisPosted Jun 9, 2022, 2:37 PM
@Sachin Singh , I Finally found a solution with your suggested code
John DavisPosted Jun 9, 2022, 2:10 PM
@Sachin Singh Can you please explain? my project is an Rest api project cloned from
https://www.c-sharpcorner.com/article/jwt-authentication-with-refresh-tokens-in-net-6-0/
Sachin SinghPosted Jun 9, 2022, 10:34 AM
John DavisPosted Jun 9, 2022, 8:34 AM
@Sachin Singh Thank you, but it returns me
Sachin SinghPosted Jun 9, 2022, 8:31 AM
Amit MohantyPosted Jun 9, 2022, 4:16 AM