pol*_*kop 1 c# asp.net-mvc email-integration
今天我正在尝试关注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);
}
Run Code Online (Sandbox Code Playgroud)
这是我的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; }
}
Run Code Online (Sandbox Code Playgroud)
对我的任何建议,真的很感谢你们所做的一切帮助.
小智 6
你能做的最简单的事情是:
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的工作.
| 归档时间: |
|
| 查看次数: |
9663 次 |
| 最近记录: |