Last post Aug 07, 2018 06:49 AM by Brando ZWZ
Aug 06, 2018 08:46 PM|RateFor|LINK
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()))
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 ApplicationUserManagerPublic 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
code = userManager.GeneratePasswordResetToken(UserID)
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.
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.
Aug 07, 2018 06:49 AM|Brando ZWZ|LINK
According to your description, I suggest you could follow below steps to enable the userprofile.