Asp.net-Mvc

如何在 asp.net core mvc 中配置確認電子郵件令牌的生命週期

  • September 29, 2020

我正在嘗試延長確認電子郵件和密碼重置電子郵件的使用壽命,但我無法做到。目前我正在使用 Asp.net core 1.0.1,如果這有幫助的話。

一些提示甚至更好的程式碼,將不勝感激。

謝謝

也許它會幫助某人=)

只需這樣做:

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

這對我有用。

Create 方法中的以下程式碼更改(在 App_Start\IdentityConfig.cs 文件中)將令牌設置為在 3 小時後過期。

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

希望這可以幫助。

引用自:https://stackoverflow.com/questions/44027058