gpt4 book ai didi

c# - ASP.net Identity Framework - 重新发送确认电子邮件

转载 作者:太空狗 更新时间:2023-10-29 20:30:07 27 4
gpt4 key购买 nike

我正在为我的 ASP.net 站点设置身份框架 (2?)。我有确认电子邮件,但我不知道在哪里或如何允许用户请求重新发送确认电子邮件。

我在 this 中找到了“重新发送电子邮件确认链接”部分,但那是为 MVC 编写的(我对此一无所知)。

有人能给我指出正确的方向或给我一些示例代码吗?

谢谢

我使用的是普通身份框架。

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);

最佳答案

好吧,结果并不是很痛苦。我遗漏了丑陋的部分,我将他们上次请求的日期时间存储在用户的电话号码字段中。 :) 我还没有学会如何将自定义字段添加到 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);
}

关于c# - ASP.net Identity Framework - 重新发送确认电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37623502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com