Unable to access CreateAsync in User Manager

I’m trying to use the new Asp.Net Identity system. I’ve searched this in asp.net site and able to find a tutorial here.

I’ve created Register action and appropriate view for it. But Unable to code it further as I’m struck using User Manager in Identity System.

To be precise, It’s here.

var result = await UserManager.CreateAsync(user, register.Password);

The UserManager class throws an exception

Using the generic type 'Microsoft.AspNet.Identity.UserManager<TUser,TKey>' requires 2 type arguments

My question is why did the author of the tutorial did not get any sort of exceptions ? Am I missing any dependencies ?

It seems like the documentation is not so perfect in asp.net site as well.

Any help would be appreciated.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

var result = await UserManager.CreateAsync(user, register.Password);

The UserManager in the above statement is not a Class as I’ve expected. Its a property of type UserManager<ApplicationUser>.

So, at the beginning just declared a property as

public UserManager<ApplicationUser> UserManager { get; private set; }

And now I can use the Async version for creating users. The following statement works.

var result = await UserManager.CreateAsync(user, register.Password);

Method 2

Have you referenced “Microsoft.AspNet.Identity.Core, Version=2.0.0.0”?

Microsoft ASP.NET Identity Core 2.0.0

Update 1
I’ve just looked back at some code where I have done this, and it looks like I ended up using the non-async version:

var result = userManager.Create(user, password);

Although this doesn’t answer your specific question, it may help.

Update 2
Check you have the following using statements:

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;

Method 3

So, at the beginning just declared a property as

 public UserManager<ApplicationUser> UserManager { get{return _userManager;} private set{} }

And

  private AppUserManager _userManager 
{
  get { return HttpContext.GetOwinContext().GetUserManager<AppUserManager>();}
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x