How could I use ApplicationUserManager in c# entity-framework unity-container user-management


I've developed a controller with the nameProfileContoller in my submission. I must create an instance of in this controller ofApplicationUserManager But I have no idea how to make a fresh instance of it. I tested the code below:

private ApplicationUserManager _userManager = Current.GetOwinContext().GetUserManager<ApplicationUserManager>();

nonetheless, I encountered the following error:

The name Current does not exist in the current context

My initial query is, "How am I able to do this?" This line of code will be accessed:

return View(await _userManager.FindByNameAsync(username));

I also employ anUnityContainer . My second inquiry is: Can I also register theApplicationUserManager relating to the interactionIUser or IUserStore 1.


Later, I discovered something along these lines:

private UserManager<ApplicationUser> _userManager = UserManager<ApplicationUserManager>();

But I get the following error:

Non-invocable member UserManager<TUser> cannot be used like a method.

I is unable to distinguish between the forest and the trees because of this additional "user manager." Can you one more tell me what all the "user managers" mean and how they work?

1 Since I'm unsure of the distinction between the two, would you please explain it as well?

2/15/2016 7:32:23 PM

Accepted Answer

For me, this works:

using System.Web;  //make sure you have this using

    private ApplicationUserManager _userManager;
    public ApplicationUserManager UserManager
            if (_userManager == null && HttpContext == null)
                return new ApplicationUserManager(new Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>(db));
            return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
        private set
            _userManager = value;
2/15/2016 5:59:22 PM

Popular Answer

I've discovered the error Steve Greene mentioned on this inquiry. All I was lacking was a using sentence.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow