User297437924 posted
I wrote the following code, some of it pasted from a MSDN page:
Public Class ApplicationUserManager
Inherits UserManager(Of ApplicationUser)
Public Sub New()
MyBase.New(New UserStore(Of ApplicationUser)(New ApplicationDbContext()))
End Sub
End Class
then I did the following, which is an attempt to generate a token that I can email to a user who has forgotten his password:
Private Shared Provider As DpapiDataProtectionProvider = New DpapiDataProtectionProvider("rateForSuccess")
Private Shared userManager As New ApplicationUserManager
Public Shared Function GenerateResetPassword(ByVal UserID As String) As String
Dim code As String
If Provider IsNot Nothing Then
Dim oTokenProvider As Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider(Of ApplicationUser)
oTokenProvider = New DataProtectorTokenProvider(Of ApplicationUser)(Provider.Create("ASP.NET Identity"))
oTokenProvider.TokenLifespan = TimeSpan.FromDays(1)
userManager.UserTokenProvider = oTokenProvider
End If
code = userManager.GeneratePasswordResetToken(UserID)
Return code
End Function
This gives the following error (see below). The error does not occur when I run the program in Visual Studio on my local PC, but does occur when I ftp all my files to a remote server and try it there. Any help is appreciated.
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.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: 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's user context, which may be the case
when the thread is impersonating.