I’m having a rough time with this membership stuff.
OK, so, it’s really odd. I can register a user. I can register, I can login. However, when I go to register ANOTHER user the user isn’t saved in the database and I get a Membership credential verification failed event when the user tries to login (I assume because the user is never being saved).
Here is the code I am using to save a new user.
On the page:
protected void btnRegister_Click(object sender, EventArgs e) { if (false == ValidatePage()) return; FormsAuthentication.SignOut(); MembershipCreateStatus status; Data.User user = UserManager.CreateUser(txtEmail.Text.Trim(), txtPassword.Text.Trim(), out status); switch (status) { case MembershipCreateStatus.Success: UserManager.Save(user); break; default: lblMessage.Text = status.ToString(); break; } Response.Redirect('~/login.aspx'); }
the CreateUser method:
public static User CreateUser(string username, string password, out MembershipCreateStatus status) { using (TransactionScope transaction = new TransactionScope()) { MembershipUser aspnetUser = Membership.CreateUser(username, password, username, null, null, true, out status); User hqUser = null; if (status == MembershipCreateStatus.Success) { hqUser = new User(); //these properties are only for issues //that won't blow up. They can be safely removed from the system. //the aspnet membership tables take care of this stuff for us. hqUser.LastLoginDate = DateTime.Now; hqUser.DateCreated = DateTime.Now; //end properites. hqUser.Email = username; hqUser.MembershipID = (Guid)aspnetUser.ProviderUserKey; Save(hqUser); } transaction.Complete(); return hqUser;
}}
The extra save method is for saving the user in the app’s database. The user is not getting into the membership database though so I know it’s dying before that.
anyone see anything obvious that’s burning me? Thanks!
Have you checked to see this is not a problem with password complexity? I know I have had issues with this in the past…