1

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?

6
  • are you sure error prompting on this line? Commented Mar 7, 2017 at 10:53
  • It throws on this line when on Debug. Commented Mar 7, 2017 at 10:55
  • What is userId? What type? Commented Mar 7, 2017 at 11:05
  • I create the user above this line and gets the created users id in to this. in my case this is an int. Commented Mar 7, 2017 at 11:23
  • 1
    According to Microsoft, this method expects a TKey argument. Check out this thread, get a proper user object and pass its `id´ property instead: stackoverflow.com/questions/22755700/… Commented Mar 7, 2017 at 11:32

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

In my case I have both projects in same solution. So I hope the machine key will be the same. I tried with machinekey in web.config also. Still the same.
Its all about token. If you call ConfirmEmailAsync then the token is passed to VerifyUserTokenAsync(userId, "Confirmation", token) where “Confirmation” is a purpose.
@AsiriDissa: Machine key has nothing to do with the solution. Machine keys, by default, are generated per site in IIS. If you need to share the machine key between sites, you need to generate one in IIS and then apply it in the Web.config of each site manually.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.