public ActionResult Create(RegisterModel register, string[] roles=null) { if(ModelState.IsValid) { WebSecurity.CreateUserAndAccount(register.UserName, register.Password); roleProvider.AddUsersToRoles(new[]{register.UserName},roles ); return RedirectToAction("Index"); } return View(register); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }