public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { model.FullName }); WebSecurity.Login(model.UserName, model.Password); Roles.AddUserToRole(model.UserName, model.Role); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register() { if (WebSecurity.IsAuthenticated) return RedirectToAction("Index", "Home"); this.CreateRoles(); RegisterModel Model = new RegisterModel(); return View(Model); }