1

I am trying to customize the registration process of Asp.Net Identity(In web-API project). Is it possible to register a new user with PhoneNumber instead of Email with web-API?

Also, the rest of the features of the Identity framework should work with this new approach?

Which challenges would a programmer face with this approach?

Tried changing Email to PhoneNumber in RegisterBindingModel.cs as:

    [Required]
    [Display(Name = "Mobile number")]
    public string PhoneNumber { get; set; }

The original code was:

    [Required]
    [Display(Name = "Email")]
    public string Email{ get; set; }

Changes Made in AccountController.cs

var user = new ApplicationUser() { UserName = model.PhoneNumber, PhoneNumber = model.PhoneNumber };

        IdentityResult result = await UserManager.CreateAsync(user, model.Password);

The expected result is A new user register with just PhoneNumber.

The actual result is, Error - "Email cannot be null or empty" which is coming from ModelState.

Catalyst
  • 465
  • 6
  • 14
  • Have you tried setting the `User.RequireUniqueEmail` property in `services.AddIdentity` to `false`? I assumed this is an _asp.net core_ project. – bolkay Jun 12 '19 at 12:12
  • @bolkay, it's a .net framework web-API project. – Catalyst Jun 12 '19 at 12:18

1 Answers1

0

The following code change in IdentityConfig.cs worked:

RequireUniqueEmail = false

And, Identity framework is also checking for duplicate entries with the error:

"Name 9xxxxxxx8x is already taken"

Credit to: @Rudy Asp.Net Identity save user without email

Catalyst
  • 465
  • 6
  • 14