Asiri Dissanayaka
Asiri Dissanayaka

Reputation: 510

ASP.Net Identity GenerateEmailConfirmationTokenAsync fails

I am working on a MVC project to separate identity stuff from the startup MVC project. On user registration when executes the line

UserManager.GenerateEmailConfirmationTokenAsync(userId)

it will throw System.ArgumentException with message

If a list of purposes is specified, the list cannot contain null entries or entries that are comprised solely of whitespace characters. Parameter name: purposes

Stack trace

at System.Web.Security.MachineKey.Protect(Byte[] userData, String[] purposes)
   at Microsoft.Owin.Host.SystemWeb.DataProtection.MachineKeyDataProtector.Protect(Byte[] userData)
   at Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CallDataProtectionProvider.CallDataProtection.Protect(Byte[] userData)
   at Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider`2.<GenerateAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.Identity.UserManager`2.<GenerateUserTokenAsync>d__fe.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Robot.ACG.Web.Controllers.AccountController.<Register>d__15.MoveNext() in...

Any Ideas?

Upvotes: 1

Views: 2581

Answers (2)

Muhammad Saqlain
Muhammad Saqlain

Reputation: 2212

GenerateEmailConfirmationTokenAsync generates a token. Problem might come from your different servers:

If your token was generated on one server, and then attempting to validate it on another. Reason for that is that the token is protected via MachineKey.Protect. That is configured on OWIN initialisation.

From Max Vasilyev, Trailmax Tech.

Upvotes: 1

Pieter van Kampen
Pieter van Kampen

Reputation: 2077

I think your problem is that you should not pass an Id, but a user, at least when you are using asp.net Core:

UserManager.GenerateEmailConfirmationTokenAsync(user)

Upvotes: 0

Related Questions