I implement the reset password functionality on my site using the built-in UserManager class that ships with ASP.NET 5.
Everything works fine in my dev environment. However, as soon as I try it on a production site that runs as an Azure site, I get the following exception:
System.Security.Cryptography.CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread user context, which may be the case when the thread is impersonating.
This is how I configure the UserManager instance:
var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider(SiteConfig.SiteName); UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<User>(provider.Create(ResetPasswordPurpose));
Then I generate the token in this way (to send the user an email so they can make sure that they really want to reset their password):
string token = UserManager.GeneratePasswordResetToken(user.Id);
Unfortunately, when it works on Azure, I get the exception above.
I searched Google and found this possible solution . However, this did not work, and I still get the same exception.
According to the link, this has something to do with session tokens that do not work on a web farm such as Azure.
Andrew May 4 '14 at 11:16 2014-05-04 11:16
source share