title: How to fix 'Invalid Token' on ASP.NET Identity Email Confirmation
body: <p>I'm trying to have the confirm email validate a new user account. The token is created and emailed to the user which receive an email with a link to validate the account. When the user clicks on the link, I'm getting INVALID TOKEN.</p>
  
  <p>It is hosted on Godaddy (not sure if it makes any difference)</p>
  
  <p>While debugging the code, I find out that the token being sent to validate is the same generated initially, with the difference that now its lowercase, can this be the problem?</p>
  
  <p>The code to generate the token and email it</p>
  
  <pre><code>private async Task&lt;string&gt; SendEmailConfirmationTokenAsync(string userID, string subject)
  {
     string _code = await UserManager.GenerateEmailConfirmationTokenAsync(userID); 
     var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = userID, code = _code }, protocol: Request.Url.Scheme);
     await UserManager.SendEmailAsync(userID, subject, "Please confirm your account by clicking &lt;a href=\"" + callbackUrl + "\"&gt;here&lt;/a&gt;");
  
     return callbackUrl;
  }
  </code></pre>
  
  <p>To confirm the token/email:</p>
  
  <pre><code>[AllowAnonymous]
  public async Task&lt;ActionResult&gt; ConfirmEmail(string userId, string code)
  {
      if (userId == null || code == null)
      {
          return View("Error");
      }
  
      var result = await UserManager.ConfirmEmailAsync(userId, code);
      if (result.Succeeded)
      {
          return RedirectToAction("Create", "Users", new { id = userId });
      }
  
      AddErrors(result);
      ViewBag.errorMessage = "Error: " + result.Errors;
      return View("Error");
  }
  </code></pre>
  
  <p>Also I added machineKey to web.config.</p>
  
  <pre><code>&lt;machineKey validationKey="key" decryptionKey="key" validation="SHA1" decryption="AES" /&gt;
  </code></pre>
  
  <p>All the time I'm getting the error INVALID TOKEN</p>