0

I am getting this error when am trying to use UserManager.CreateAsync(user, reg.password) code. Please help. and one more thing i installed the package aspnet.identity.core package. But i cant reference it. When i try to reference it using Using i can't find the package.

        if (ModelState.IsValid)
        {
            var user = new ApplicationUser() { UserName = reg.username };
            var result = await UserManager.CreateAsync(user, reg.password);
              if (result.Succeeded)
            {
                await SignInAsync(user, isPersistent: false);
                return RedirectToAction("Index", "Account");
            }
            else
            {
                AddErrors(result);
            }
JLRishe
  • 99,490
  • 19
  • 131
  • 169
Vinoth Rao
  • 53
  • 2
  • 6

1 Answers1

5

The problem here is that your code is trying to call CreateAsync() directly on the UserManager<TUser> class, whereas .CreateAsync() needs to be called on an instance of UserManager<TUser>.

In the boilerplate code provided with the Identity package, this is accomplished with a property defined in the AccountController:

public ApplicationUserManager UserManager
{
    get
    {
        return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
    }
    private set
    {
        _userManager = value;
    }
}

Do you have a property like this available in your controller?

JLRishe
  • 99,490
  • 19
  • 131
  • 169