2

What is the best way to collect all relevant information user, role, and profile information on the registration page. My current approach is to set additional fields in the register model:

public class RegisterModel
{
    [Required]
    [Display(Name = "Email")]
    [DataType(DataType.EmailAddress)]
    public string UserName { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }

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

See Role as the last item. I plan to add profile information here as well.

Then in my controller I do this.

public ActionResult Register(RegisterModel model)...
 WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
 WebSecurity.Login(model.UserName, model.Password);
 Roles.AddUserToRole(model.UserName, model.Role);

Is this ok to pass these additional data elements even though they are not part of the UserProfile class? What I am doing works but it just seems wrong.

Xaxum
  • 3,545
  • 9
  • 46
  • 66

0 Answers0