.Net Memberhip Provider Does Not Detect Email Duplication

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.

+4
source share
2 answers

By default, only usernames must be unique. If you also need unique email addresses, then you must set this in the Web.config entry for the MembershipProvider.

sort of

 <membership> <providers> <add name="AspNetSqlMembershipProvider" [...] requiresUniqueEmail="true" [...] /> </providers> </membership> 
+4
source

The only thing that comes to mind is to make sure model.Email matters. Another thing you can check is to look at the default membership provider tables on the SQL server to check which values โ€‹โ€‹are stored.

0
source

Source: https://habr.com/ru/post/1412461/


All Articles