Question

When I create a user, they can't login until I go into the asp.net configuration and save them. I actually don't change any settings, I just press the save button and then they can login in. What I would like to do is to have the user be able to login once they are created, but I can't seem to get it to work. Here is my code for the CreatedUser method:

 protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
 {
     CustomerProfile adminProfile = CustomerProfile.GetProfile();
     string username = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text.Trim();

        CustomerProfile createdUser = CustomerProfile.GetProfile(username);
        createdUser.CustomerID = adminProfile.CustomerID;

        createdUser.Save();

        MembershipUser user = Membership.GetUser(username);

        user.IsApproved = ((CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("chkActivateUser")).Checked;

        Roles.AddUserToRole(user.UserName, "nonadmin");

    }
Was it helpful?

Solution

I figured it out. The problem was that after I created the user, the next page would display a message saying the user was created successfully with a continue button. When I clicked continue it would take me to the login page where I would try to login with the new user, but because it would try to access the admin section when I tried to login with the new user, it would not login.

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