What is default expiration timespan of GenerateEmailConfirmationTokenAsync? and what kind of errors should I get from ConfirmEmailAsync?
For ConfirmEmailAsync got Invalid token error. is there any other errors?
Once I confirm email and again I access same token then it is again confirming email. So up to what time span it will re-confirm Email and when it will show Invalid Token message?
For generate email:
string code = await userManager.GenerateEmailConfirmationTokenAsync(userId);
For confirm email:
var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = await userManager.ConfirmEmailAsync(userId, code);
if (result.Succeeded)
{
return RedirectToAction("Index", "Home");
}
Default timespan is one day but you can specify your timespan for the email expiration. After expiration, you will get "Invalid Token" error. You can change the code in the Create method(App_Start\IdentityConfig.cs file) for custom expiration timespan.
if (dataProtectionProvider != null)
{
manager.UserTokenProvider =
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"))
{
TokenLifespan = TimeSpan.FromHours(3)
};
}
Source: https://learn.microsoft.com/en-us/aspnet/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With