Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eric 27 posts 49 karma points
    Sep 30, 2010 @ 21:10
    Eric
    0

    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);

    }
    }               

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 01, 2010 @ 00:14
    Aaron Powell
    0

    That's the recommended way, can you post the errors

  • Eric 27 posts 49 karma points
    Oct 08, 2010 @ 13:53
    Eric
    0

    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

                }

    }

  • Dekker 13 posts 33 karma points
    Oct 08, 2010 @ 16:42
    Dekker
    0

    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");

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies