I'm working on an asp.net webform application and recently we add identity to it. Every thing was good till we add the ability of resetting the users password to admin privilege. In local system and debug mode this process is done with no error but when we move the published version to server an error raises that is : 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.
Thank you for helping me to solve this problem.
The code that we use is like this:
var provider = new DpapiDataProtectionProvider("IdentityProvider");
var userStore = new UserStore<IdentityUser>(new IdentityDbContext(SetCnnConnection()));
var manager = new UserManager<IdentityUser>(userStore);
manager.PasswordHasher = new Hasher();
manager.UserTokenProvider = new DataProtectorTokenProvider<IdentityUser>(provider.Create("EmailConfirmation"));
var user = manager.FindByName(userName);
var token = manager.GeneratePasswordResetToken(user.Id);
password = GenerateRandomPassword(null);
var result = manager.ResetPassword(user.Id, token, password);
message = result.Errors.ToList();
return result == IdentityResult.Success;