I am using Identity v2
and need to send an Email from Web Api
Controller using the UserManager.SendAsync
method which is OWIN Middleware component. But I don't know how do I access the UserManager
itself in Web Api
Controller Method. I am trying a similar approach like a Regular MVC controller but usermanager always null
. Any suggestion please?
public class MyApiController: ApiController
{
public MyApiController()
{
}
public MyApiController(ApplicationUserManager userManager)
{
UserManager = userManager;
}
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
public void SendEmail()
{
_userManager.SendAsync(...);
}
}