views:

4

answers:

0

how to validate the fields of customised registration page while registering the user using cusomised membership provider in asp.net mvc 2.0.My customised code to create the user is as follows, if(ModelState.IsValid) {

            string firstName = FirstName;
            string lastName = LastName;
            string userName = LoginId;
            string email = EmailId;
            string password = Password;
            string confirmPassword = ConfirmPassword;

            MembershipUser user = Membership.CreateUser(userName, password, email);
            Roles.AddUserToRole(userName, "User");
            UserProfile.NewUser.Initialize(userName, true);
            UserProfile.NewUser.FirstName = firstName;
            UserProfile.NewUser.LastName = lastName;

            UserProfile.NewUser.Save();

            FormsService.SignIn(userName, false /* createPersistentCookie */);
            return RedirectToAction("CreateAccountConfirmation");

        }
        else
        {
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            // Stay on the same view
            return View();
        }