Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Jul 28, 2011 @ 03:49
    Tom
    0

    Create Member Programatically using asp.net membership??

    Hi All,

    I know how to make members using the old ways but just wondering how I'd do this using the new asp.net membership stuff where I can assign a member type/group??

    MemberType memberType = MemberType.GetByAlias("publicMember");

    Member m = Member.MakeNew(name, username, email, memberType, new umbraco.BusinessLogic.User(0));

    m.Save();

     

    Roles.AddUserToRole(username, groupNode.InnerText);

     

     

  • Tom 713 posts 954 karma points
    Jul 28, 2011 @ 04:20
    Tom
    0

    MemberType memberType = MemberType.GetByAlias("publicMember");

    Member m = Member.MakeNew(name, username, email, memberType, new umbraco.BusinessLogic.User(0));

    m.Save();

    umbraco.library.RefreshContent();

     

    Roles.AddUserToRole(m.LoginName, "Public");

     

    I tried this as well just to create a member.. the only problem is that when umbraco gets in to the method and tries:

                foreach (string username in usernames) {

                    Member m = Member.GetMemberFromLoginName(username);

                    foreach (int roleId in roles)

                        m.AddGroup(roleId);

                }

           

    Member.GetMemberFromLoginName returns null... any idea why that is???

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 28, 2011 @ 08:04
    Dirk De Grave
    0

    Tom,

    Can use Membership.CreateUser(username, password, email) and you're good to go. Also make sure to catch any exceptions that may arise...

    try {
      var member = Membership.CreateUser(username, password, email);
    } catch (MembershipCreateUserException mcue) {
    //...
    }

    Hope this helps.

    Regards,

    /Dirk
     

  • Tom 713 posts 954 karma points
    Jul 28, 2011 @ 08:11
    Tom
    0

    Thanks for the reply Dirk!

    but then how would i set custom properties on that member type?

    i.e. say my member has a date of birth property?

  • Richard Soeteman 4047 posts 12900 karma points MVP 2x
    Jul 28, 2011 @ 08:54
    Richard Soeteman
    0

    I would still go for the old depricated way, much easier member.getProperty("the alias here").value = .

    If you want to use the asp.net way you can assign properties using the role provider as described in this blog post from Aaron however it would require some configuration.

    Cheers,

    Richard

  • Anthony Candaele 1197 posts 2049 karma points
    Jul 16, 2012 @ 20:56
    Anthony Candaele
    0

    Hi Richard,

    Because I don't know how to create a new member and set it's member type, I reverted to the deprecated way:

    Member.MakeNew("John Smith", membertype,new umbraco.BusinessLogic.User(0));

    However, when I try to login with the newly created member account, using the Asp.Net Login Control, I get a 'Your login attempt was unsuccesful' message

    Is it not possible to use the Asp.Net Login Control with the Member.MakeNew() method?

    Greetings,
    Anthony

  • Richard Soeteman 4047 posts 12900 karma points MVP 2x
    Jul 16, 2012 @ 22:37
    Richard Soeteman
    1

    HI Anthony,

    Yes but I think you forgot to set a password on the membertype.

    Member member = Member.MakeNew("John Smith", membertype,new umbraco.BusinessLogic.User(0));
    member.Password="SomePass";

    Hope this helps,

    Richard

  • Anthony Candaele 1197 posts 2049 karma points
    Jul 17, 2012 @ 10:28
    Anthony Candaele
    0

    Hi Richard,

    Thanks a lot, it worked :)

Please Sign in or register to post replies

Write your reply to:

Draft