Personally, I'm using the asp:CreateUserWizard control to create my wizard, and it creates the new Member as desired (but does NOT respect the default MemberTypeAlias, and therefore in the CreatedUser event, I have the same line as you to add them to the correct Role. No other registration code, just that one line (the rest is non-registration related)
Dynamically Creating members in 4.5.x
I am trying to create members dynamically and running into a lot of old out of date examples. What is the correct way in 4.5?
This is what I have so far, but its throught object reference errors.
protected void CreateMember()
{
if (Membership.GetUser(username.Text) == null)
{
MembershipUser newMember = Membership.CreateUser(username.Text, Membership.GeneratePassword(6, 3), emailAddress.Text);
}
}
That's the recommended way, can you post the errors
The problem was I wasn't setting the defaultMemberTypeAlias in the web config
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Consumers" passwordFormat="Hashed" />
Here is how I am creating the member, it works, if anyone has another way, let me know.
if (Membership.GetUser(userName.Text) == null)
{
MembershipProvider myProvider = Membership.Providers["UmbracoMembershipProvider"];
MembershipCreateStatus createStatus;
MembershipUser newMember = myProvider.CreateUser(userName.Text, confirmPassword.Text, emailAddress.Text, string.Empty, string.Empty, true, string.Empty, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
Roles.AddUserToRole(userName.Text, "Consumers");
// OTHER CODE
}
}
Personally, I'm using the asp:CreateUserWizard control to create my wizard, and it creates the new Member as desired (but does NOT respect the default MemberTypeAlias, and therefore in the CreatedUser event, I have the same line as you to add them to the correct Role. No other registration code, just that one line (the rest is non-registration related)
Roles.AddUserToRole(userName.Text, "Consumers");
is working on a reply...