Question

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!

Was it helpful?

Solution

Have you checked to see this is not a problem with password complexity? I know I have had issues with this in the past...

OTHER TIPS

You redirect the page before you are able to see the output if the status is not equal to success.

Btw. it might be better to inherit the sqlmembership provider and extend it with your own extra db inserts, at least if you are not inserting extra data. Or are you asking more than the default stuff on the first creation of the account?

Try it like this code and see what the value of the enum is in the lblMessage

protected void btnRegister_Click(object sender, EventArgs e) {

      if (!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);
            Response.Redirect("~/login.aspx");
                            break;
                    default:
                            lblMessage.Text = status.ToString();
                            break;
            }       

    }

grrgr, stupid markup thing

Hope this helps.

My first guess is that ValidatePage() return false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top