[英]ASP.Net MVC 4 SimpleMembership “Re-Send Confirmation Email”
[英]How can I send a Confirmation Email in asp.net mvc
今天,我试图遵循Shai Raiten博客中的这篇文章,当我完成本文时,createStatus返回invalidAnswer,这是我的Register操作
[HttpPost]
[AllowAnonymous]
[CaptchaValidation("CaptchaCode", "registerCaptcha", "Wrong captcha!")]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, false, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
MailHelper.SendConfirmationEmail(model.UserName);
return RedirectToAction("Confirmation", "User");
}
else
{
ModelState.AddModelError("", "Failed!");
}
}
return View(model);
}
这是我的RegisterModel.cs
public class RegisterModel
{
[Key]
public long ID { set; get; }
[Required(ErrorMessage = "Do not Skip this")]
public string UserName { set; get; }
[StringLength(500, MinimumLength = 6, ErrorMessage = "Atleast 6 characters in passwords")]
[Required(ErrorMessage = "Do not Skip this")]
public string Password { set; get; }
[Compare("Password", ErrorMessage = "Wrong confirm passwords")]
[Required(ErrorMessage = "Do not skip this")]
public string ConfirmPassword { set; get; }
public string Name { set; get; }
public string Address { set; get; }
[RegularExpression(@"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", ErrorMessage = "This is not an email")]
public string Email { set; get; }
public string Phone { set; get; }
public bool EmailConfirm { set; get; }
}
对我的任何建议,非常感谢你们提供的所有帮助。
您可以做的最简单的事情是:
bool IsEmailConfirmed
,其默认值为false
。 [HttpGet, AllowAnonymous] ConfirmEmail(string email, string token)
,该操作将针对存储在数据库中的令牌进行验证,并相应地更新IsEmailConfirmed
。 http://YOUR.SERVER/YourController/ConfirmEmail?email={0}&token={1}
,其中{0}
是用户电子邮件, {1}
是您的用户电子邮件确认令牌。 它应该返回一个视图,告诉您确认是否成功。 但是,我建议您不要重新发明轮子,而应该简单地使用Asp.Net Identity 2.0框架 ,它将为您完成所有authn和authz的工作。
请遵循以下来自ASP.Net网站的示例,该示例详细说明了如何在注册过程中发送电子邮件。
另外,我不建议您使用MD5密码hashinh,因为它已经很老了,请尝试使用SHA 256哈希进行密码加密。 http://forums.asp.net/t/1211478.aspx?How+do+I+use+Sha256+to+Encrypt+a+String+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.