Email Token Expiring After 15 mins - Asp Identity

2019-02-03 04:35发布

问题:

I'm facing a strange issue in Asp Dot Net Identity API 2.0 API.

When an user signs up, I send a confirmation email to the user. And if the user confirms his / her account within 15 mins of signing up, the "ConfirmEmailAsync" method seems to be working.

But after 15 mins, if I try to confirm the email address, I'm getting a "Invalid Token" error.

Is there a way to set the token expiry time?

A really frustrating issue and it's becoming very hard to troubleshoot.

Can anyone help please?

回答1:

Change the code in the Create method(App_Start\IdentityConfig.cs file).

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

source: http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity