Please check the code below. This is a controller of my ASP.NET Core 2.1 MVC application.
Problem is that I am already using cookie authenticated user, but the User.Identity.Name
returns null. How can I get my current auth user on .NET Core then?
[HttpPost]
public IActionResult AddMainMenu(MainMenuItems mainMenuItems)
{
string userEmail = User.Identity.Name;
return Json("success");
}
Thanks in advance.
Just use it-
var val = User.FindFirst(ClaimTypes.Email).Value;
If your claim NameIdentifier is Email then do like above. This should work. More information found here
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments