Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Oct 13, 2010 @ 13:43
    Phil Crowe
    0

    creating members with username and password

    Ive been following the documentation for how to create members programatically but theres no explanation for what the .BusinessLogic.User is...

     

                MemberType mt = MemberType.GetByAlias("UserWithProfile");

     

                //create a member

                Member m = Member.MakeNew(tbFirstName.Text + " " + tbLastName.Text, mt, new umbraco.BusinessLogic.User(tbFirstName.Text + tbLastName.Text,tbPassword.Text));

     

                //set a property value on the member

                m.getProperty("firstName").Value = tbFirstName.Text;

                m.getProperty("lastName").Value = tbLastName.Text;

                //Generate member Xml Cache

                m.XmlGenerate(new System.Xml.XmlDocument());

     

                //Save member

                m.Save();

                lblConfirmMember.Text = "Member " + tbFirstName.Text + " " + tbLastName.Text + " has been created.";

     

     

    The example in the documentation tells me to create the member like this umbraco.BusinessLogic.User(0); but doesnt explain what this does... i thought it will be the unque id for the member but that that means every member will be created with the user id '0'. it worked creating my first member but then said 'member already exsists' when i created the second. so i tried changing the code to this BusinessLogic.User(1) but then this gave me the error 'no user with id 1'. I looked at what paramters this method takes and i could pass the username and password but then this gives me this error.

     

    System.ArgumentException: No User exists with ID -1 at umbraco.BusinessLogic.User.setupUser(Int32 ID) at umbraco.BusinessLogic.User..ctor(String Login, String Password) at usercontrols_members_management_usercontrols_ucMemberLogin.btnCreateMember_Click(Object sender, EventArgs e)

     

    what is this parameter for?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 13, 2010 @ 14:21
    Dirk De Grave
    0

    You need to pass a user (backend user, not a member) as the third parameter. In most cases, if you're programmatically creating members, that would be the 'administrator' which has an id = 0. It's just a reference so you know who'd created that member, but in most cases, it's not that important, in which case you use the administrator user.

    So, instead of passing username/password to the constructor of User(String,String), use

    new umbraco.BusinessLogic.User(0);

     

    Hope this helps.

    Regards,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft