I'm using MS Identity and when I'm using a reset token to reset the password, I get this exception:

Inner Exception Type: System.Security.Cryptography.CryptographicException Inner Exception: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.

This is what the code looks:

var TheProvider = new DpapiDataProtectionProvider("Sample");
UserManager<IdentityUser> TheUserManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>());
TheUserManager.UserTokenProvider = new DataProtectorTokenProvider<IdentityUser>(TheProvider.Create("EmailConfirmation"));

string TheResetCode = TheUserManager.GeneratePasswordResetToken(TheUserMembershiptID);

IdentityResult TheResult = TheUserManager.ResetPassword(TheUserMembershiptID, TheResetCode, TheNewPassword);

I've looked around but I haven't found a solution. What do I need to change to make it work?

Thanks.

Related posts

Recent Viewed