【问题标题】:How to configure confirmation email token lifespan in asp.net core mvc如何在 asp.net core mvc 中配置确认电子邮件令牌的生命周期
【发布时间】:2017-10-17 01:06:44
【问题描述】:

我正在尝试延长确认电子邮件和密码重置电子邮件的使用寿命,但我无法做到。 目前我正在使用 Asp.net core 1.0.1,如果这有帮助的话。

非常感谢您提供一些提示甚至更好的代码。

谢谢

【问题讨论】:

标签: asp.net-mvc asp.net-core asp.net-identity password-recovery email-confirmation


【解决方案1】:

Create 方法中的以下代码更改(在 App_Start\IdentityConfig.cs 文件中)将令牌设置为在 3 小时后过期。

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

希望这会有所帮助。

【讨论】:

  • 我提到我使用的是Asp.net core mvc,所以没有任何App_Start\IdentityConfig.cs。无论如何,谢谢你:)
【解决方案2】:

也许它会帮助某人=)

这样做:

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

这对我有用。

【讨论】:

  • 它在我的项目中不起作用。我正在使用 .Net Core 3.1
  • 这不会也增加 PasswordRest 令牌的 LifeSpan 吗?我很确定 EmailConfirmation 和 PasswordReset 令牌都使用相同的 DataProtectionTokenProvider 实例。
猜你喜欢
  • 2021-06-04
  • 1970-01-01
  • 2016-12-11
  • 1970-01-01
  • 2018-12-23
  • 1970-01-01
  • 2016-06-07
  • 2016-08-06
  • 2014-09-16
相关资源
最近更新 更多