How to use UserManager in my controller?
What the title says, what I'm doing currently:
But Visual Studio doesn't recognize the UserManager<IdentityUser> type:
'UserManager<>' is an ambiguous reference between 'Microsoft.AspNet.Identity.UserManager<TUser>' and 'Microsoft.AspNetCore.Identity.UserManager<TUser>'
When I change it to private Microsoft.AspNet.Identity.UserManager<IdentityUser> _userManager;
I get this error:
'Microsoft.AspNetCore.Identity.IdentityUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserManager<TUser>'. There is no implicit reference conversion from 'Microsoft.AspNetCore.Identity.IdentityUser' to 'Microsoft.AspNet.Identity.IUser<string>'.18 Replies
Try
IdentityUser<string>
maybe?As in
private IdentityUser<string> _userManager;
?Yeah
And in the constructor
it builds, but then when I go to the view I get:
Huh
Not sure, then
I wonder if you need to create your own user type...? Probably not
Ah, wait
UserManager<IdentityUser<string>>
not just IdentityUser<string>
Get the same ambiguous reference error from before. Could it be soething wrong in the Program.cs?
Not sure tbh
I removed the ambiguity by changing it to Microsoft.AspNetCore.Identity.UserManager<IdentityUser<string>>
and now it seems to be working, at least the instance of that objet recognizes a changepasswordasync method
Ah, nice
Still get the invalid exception tho
on the view
What invalid exception?
Gipper
it builds, but then when I go to the view I get:
Quoted by
<@333337750897950720> from #How to use UserManager in my controller? (click here)
React with ❌ to remove this embed.
Huh
At this point, I'd just create a new Razor Pages project with scaffolded Identity and see how they do it
Fixed it, I think. It was the program.cs where for some reason I had a call to AddDefaultIdentity instead of just AddIdentity
Ah
The controller at least constructs fine now even with usermanager and signinmanager
Nice