How to configure confirmation email token lifespan in asp.net core mvc

The following code change in the Create method (in the App_Start\IdentityConfig.cs file) sets the tokens to expire in 3 hours.

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

Hope this helps.


Maybe it will help someone=)

Just do this:

    public void ConfigureServices(IServiceCollection services)
    {
        // ...
        services.Configure<DataProtectionTokenProviderOptions>(options =>
        {
            options.TokenLifespan = TimeSpan.FromDays(2); // Sets the expiry to two days
        });
    }

This works for me.