title: MVC 5, Invalid Token
body: <p>I've seen this discussed a few times but I still can't solve it.</p>
  
  <p>My registration process works well 99% of the time.  But the occasional time I get an invalid token error when confirming an email address (via a link in an email).  I'm even URL encoding/decoding the token now too, but I still get the occasional error.</p>
  
  <p>Register action:</p>
  
  <pre><code>string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
  code = System.Web.HttpUtility.UrlEncode(code);
  var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
  </code></pre>
  
  <p>and Confirm action:</p>
  
  <pre><code>code = System.Web.HttpUtility.UrlDecode(code);
  var result = await UserManager.ConfirmEmailAsync(userId, code);
  </code></pre>
  
  <p>I can confirm each 'failing' user does have a Security Stamp.  And the name/username doesn't appear to contain any dodgy characters.</p>
  
  <p>Is there anything else I can check?</p>