I am relatively new to .Net / MVC3 and am working on a C #, MVC3, EF4 application that uses the default membership provider. From my reading, it should automatically receive duplicate letters, but it seems that this is not so, and I'm not sure why. What I really need to find out is to find to see if the correct fragments exist, and for what reason (why) it might not do a validation check (most / all the others seem to do, for example, duplicate usernames or invalid formats passwords, etc., when only a duplicate letter does not come across.)
Settings include adding new users to a specific role and redirecting to the welcome page "first time".
Here is the code:
// 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); }
Here are the (untouched) validation methods:
#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.";
and etc.
source share