I\'m trying to get the user id in an ASP.NET Core 2.1 MVC project.
However, I was only able to get the email. I\'m almost sure there has to be a 1/2 line way to get
You need to inject dependency in the controller like shown below:
[Authorize]
public class AccountController: Controller
{
private readonly UserManager _userManager;
public AccountController(UserManager userManager)
{
_userManager = userManager;
}
}
Now, you can use below code anywhere inside that controller to get user details.
var user = await _userManager.FindByEmailAsync(model.EmailID);
Now, You can use user.Id to get userId.