我为我的ASP.net网站设置了Identity Framework(2?)。我有确认电子邮件,但我无法确定允许用户请求重新发送确认电子邮件的地点或方式。
我发现此部分'重新发送电子邮件确认链接'在this,但这是为MVC写的(我根本不知道)。
有人能指出我正确的方向还是给我一些示例代码?
由于
我正在使用股票Identity Framework。
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
答案 0 :(得分:2)
嗯,这并不是很痛苦。我遗漏了丑陋的部分,我将其最后一个请求的dateTime存储在用户的电话号码字段中。 :)我还没有学习如何将自定义字段添加到aspNetUsers表中。使用dateTime,我可以限制他们要求重新发送的频率......只是因为他们试图发送别人的电子邮件。
private ApplicationUser _currentUser;
private ApplicationUserManager _manager;
protected ApplicationUserManager Manager
{
get { return _manager ?? (_manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>()); }
}
protected ApplicationUser CurrentUser
{
get { return _currentUser ?? (_currentUser = Manager.FindById(User.Identity.GetUserId())); }
}
protected void Page_Load(object sender, EventArgs e)
{
if (CurrentUser == null || !User.Identity.IsAuthenticated)
{
Response.Redirect("~/account/register.aspx");
}
else if (User.Identity.IsAuthenticated && CurrentUser.EmailConfirmed)
{
alreadyConfirmed.Visible = true;
}
else if (!minTimeElapsedSinceLastRequest())
{
NotEnoughTimeLiteral.Text = "A resend occurred on " + CurrentUser.PhoneNumber + ". Please wait longer before your next request";
notEnoughTimeFlag.Visible = true;
}
else
{
idResendButton.Enabled = true;
}
}
protected void ResendConfirmationEmailClick(object sender, EventArgs e)
{
string currentUserId = User.Identity.GetUserId();
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
string code = Manager.GenerateEmailConfirmationToken(currentUserId);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, currentUserId, Request);
Manager.SendEmail(currentUserId, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
setUsersLastResendDateTime(CurrentUser);
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
答案 1 :(得分:2)
要将重新发送电子邮件确认添加到ASP.NET core 2. *和3. *中的Identity Framework中,您应通过.Net CLI或Visual Studio搭建代码,如here所示
这是在Visual Studio中执行的操作。
答案 2 :(得分:0)
您可以在管理控制器中使用SendVerificationEmail
。
有关更多信息,请查看此链接[https://github.com/aspnet/AspNetCore/issues/5410]