How do we get the current user, within an secure ApiController action, without passing the userName or userId as a parameter?
We assume that this is available, beca
Karan Bhandari's answer is good, but the AccountController added in a project is very likely a Mvc.Controller
. To convert his answer for use in an ApiController change HttpContext.Current.GetOwinContext()
to Request.GetOwinContext()
and make sure you have added the following 2 using
statements:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
In .Net Core use User.Identity.Name
to get the Name claim of the user.