Wednesday, 15 June 2011

c# - How to allow user to register with duplicate UserName using Identity Framework 1.0 -


I want to develop an application using the Identity Framework 1.0 in MVCL which allows users to register with the same username used by another user.

When the user is deleted, then I deleted my IsDeleted custom property In this situation, another user's username is set to true IsDeleted

but the default UserManager .CreateAsync can use (user, password); The method is prevented from doing so.

I ValidateEntity method IdentityDbContext like

  protected override DbEntityValidationResult ValidateEntity (DbEntityEntry entityEntry, IDictionary & LT; Object, Object & item;} {if (! (EntityEntry = Faucet) & amp; (entityEntry.State == EntityState.Added)} {ApplicationUser User = Entry entry as ApplicationUser; Antity; If ((user = null) & amp ;! & amp; this.Users.Any & LT; ApplicationUser & gt; (U = & gt; string.Equals (u.UserName, user.UserName) & amp; & amp; u.IsDeleted == false)) {new DbEntityValidationResult return (entityEntry, a new list of & lt; DbValidationError & gt; ()) {ValidationErrors = {new DbValidationError ( "user", String.Format (CultureInfo.CurrentCulture, "", New object [] {user.UserName}))}}; } IdentityRole role = unit entry. Identity recognition; If ((role = null) & amp ;! & amp; this.Roles.Any & LT; IdentityRole & gt; (r = & gt; string.Equals (r.Name, role.Name))) {new DbEntityValidationResult return (EntityEntry, a new list of & lt; DbValidationError & gt; ()) {Validation Arars = {new Dibivalideteshn error ( "role", Stringkformet (culture Info. Kantentkalcr, "", new object [] {role.Name} ))}}; }} Return base.ValidateEntity (Entity Entry, Item); }  

Here is my registration method where user is created

  public async Tasks & lt; ActionResult & gt; Register (RegisterViewModel model) {if (ModelState.IsValid) {var user = new ApplicationUser () {username = model.UserName, email = model.Email.ToLower (), CreatedBy = model.UserName, CreatedDate = DateTime.UtcNow, }; User.ConfirmedEmail = false; Var Results = Wait _accountService.CreateAsync (User, model.Password); If (result successful) {TempData ["MessageConfirm"] = user.Email; Return Redirect Action ("Confirm", "Account"); } Other {Eenders (Results); }} // If we got this far away, then some failed, see the form return view (model); }   

ValidateEntity method when wait _accountService.CreateAsync (user, model.Password) should be executed; executes. But after implementing it, it fulfills the register method execution. So the result throws error.

Any suggestions how can I get it?


No comments:

Post a Comment