我對.Net/MVC3相對較新,並且正在使用默認成員資格提供程序的C#,MVC3,EF4應用程序。從我的閱讀中,它應該會自動收到重複的電子郵件,但它似乎並沒有這樣做,我不知道爲什麼。我真的需要搞清楚的是在哪裏看,看是否正確件到位,以及爲什麼它可能無法做到這一點的驗證檢查的原因(S)(好像做大部分/所有的人,像重複用戶名或密碼無效格式等,只有重複的電子郵件不會被抓到。).Net會員供應商沒有捕獲電子郵件複製
自定義包括添加新用戶到一個特定的角色,並重定向到一個「第一次」歡迎頁面。
下面是代碼:
// POST: /Account/Register
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
Roles.AddUserToRole(model.UserName, "Registered");
//return RedirectToAction("Index", "Home");
return RedirectToAction("Acceptance", "Account");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
這裏是(不變)的驗證方法:
#region Status Codes
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
{
// See http://go.microsoft.com/fwlink/?LinkID=177550 for
// a full list of status codes.
switch (createStatus)
{
case MembershipCreateStatus.DuplicateUserName:
return "User name already exists. Please enter a different user name.";
case MembershipCreateStatus.DuplicateEmail:
return "A user name for that e-mail address already exists. Please enter a different e-mail address.";
等
丁丁丁!給那個Mystere男人一支雪茄!我得到了測試此驗證消息:該電子郵件地址的用戶名已經存在。請輸入不同的電子郵件地址。 –