Last post Sep 04, 2017 06:48 PM by michael_c
Sep 03, 2017 09:40 PM|michael_c|LINK
I just updated our .Net Core web application from V1.1 to V2.0. After making the necessary changes to accommodate namespace changes, etc., I started testing. Registration and Login via OAuth providers (Google and Facebook) worked correctly, but when I
went to create a local account, the Confirm Email process failed (UserManager.ConfirmEmailAsync). When Registering, the new account is being created correctly, and the user receives the confirmation email message. Clicking the included link takes them to
the correct page to confirm their email address, but when ConfirmEmailAsync tries to validate the token, it fails. It does not throw an exception; the IdentityResult returned from the method has Succeeded as false. My code is fairly straightforward:
// GET: /Account/ConfirmEmail
public async Task<IActionResult> ConfirmEmail(string userId, string code)
if (userId == null || code == null)
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
result = await _userManager.ConfirmEmailAsync(user, code);
catch (InvalidOperationException ioe)
_logger.LogError(1, ioe, "Email Confirmation failure");
ViewBag.errorMessage = ioe.Message;
ViewBag.errorMessage = "Confirm Email failed";
Any suggestions on how to resolve this issue would be most appreciated. (And yes, it was working correctly under Core 1.1)
Sep 04, 2017 05:25 AM|Jean Sun|LINK
Please check the errors property of the IdentityResult to see if there any errors.
You can find the source code of the ConfirmEmailAsync method from the link :
public virtual async Task<IdentityResult> ConfirmEmailAsync(TUser user, string token)
var store = GetEmailStore();
if (user == null)
throw new ArgumentNullException(nameof(user));
if (!await VerifyUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, ConfirmEmailTokenPurpose, token))
await store.SetEmailConfirmedAsync(user, true, CancellationToken);
return await UpdateUserAsync(user);
Based on your description, it seems that this error happens at the last line(return await UpdateUserAsync(user);) of the method. You can find the source code of the UpdateUserAsync in the above link too, you can check the source code and try locate what's
wrong on your side.
Sep 04, 2017 06:13 PM|michael_c|LINK
@Jean Sun - If I remember correctly, the error message was just "Validation failed" or words to that effect. It did not specify what aspect of the validation process failed.
Sep 04, 2017 06:27 PM|michael_c|LINK
@Jean Sun - I went back and checked and found out that the IdentityResult.Errors collection is empty.
Sep 04, 2017 06:48 PM|michael_c|LINK
@Jean Sun - It turns out your assessment was correct. The store method UpdateUserAsync was returning an IdentityResult.Failed set to true, because of an error in the Repository class (remember I said I updated everything to Core V2; that's where the bug
appeared). Thank you for you help.