Saturday, February 9, 2013

Create User In MVC Membership


 if (ModelState.IsValid)
                {
                    MembershipCreateStatus membershipCreateStatus;
                    Membership.CreateUser(userRegistration.userName, userRegistration.password, userRegistration.emailID, userRegistration.securityQuestion, userRegistration.securityAnswer, true, out membershipCreateStatus);

                    if (membershipCreateStatus == MembershipCreateStatus.Success)
                    {
                        Roles.AddUserToRole(userRegistration.userName, "UserRole");
                        return RedirectToAction("Index", "Account");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Registration Unsuccessful, Please Try again");
                        return View(userRegistration);
                    }
                }
                else
                {
                    return View(userRegistration);
                }

No comments:

Post a Comment