GenerateEmailConfirmationTokenAsync 默认过期时间跨度

Sin*_*cha 7 c# owin asp.net-mvc-5 asp.net-identity

GenerateEmailConfirmationTokenAsync 的默认过期时间跨度是多少?我应该从 ConfirmEmailAsync 得到什么样的错误?

对于 ConfirmEmailAsync 有无效令牌错误。还有其他错误吗?

一旦我确认电子邮件并再次访问相同的令牌,它就会再次确认电子邮件。那么它会在多长时间内重新确认电子邮件以及何时会显示无效令牌消息?

对于生成电子邮件:

     string code = await userManager.GenerateEmailConfirmationTokenAsync(userId);
Run Code Online (Sandbox Code Playgroud)

对于确认电子邮件:

    var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
    var result = await userManager.ConfirmEmailAsync(userId, code);

    if (result.Succeeded)
    {
       return RedirectToAction("Index", "Home");
    }
Run Code Online (Sandbox Code Playgroud)

Nee*_*hta 7

默认时间跨度为 1 天,但您可以指定电子邮件到期的时间跨度。到期后,您将收到“无效令牌”错误。您可以更改 Create 方法(App_Start\IdentityConfig.cs 文件)中的代码以自定义到期时间跨度。

if (dataProtectionProvider != null)
{
    manager.UserTokenProvider = 
            new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"))
            {                    
                 TokenLifespan = TimeSpan.FromHours(3)
            };
}
Run Code Online (Sandbox Code Playgroud)

来源:https : //docs.microsoft.com/en-us/aspnet/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity