Copied to clipboard

Flag this post as spam?

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


  • keilo 568 posts 1023 karma points
    Aug 04, 2016 @ 15:05
    keilo
    0

    Setting Custom property witin MembershipProvider

    How to set a custom property of a member with the new API?

    I have a very simply custom MembershipProvider like

    public class customMembershipProvider: umbraco.providers.members.UmbracoMembershipProvider{
    ....
    ...
     MembershipUser member = Membership.GetUser(username);
        if (member == null)
        {
          member = Membership.CreateUser(username, password, email);
          Roles.AddUserToRole(member.UserName, DEFAULT_MEMBER_GROUP);
          // the above works fine, but setting property wont work:
         member.SetProperty("customproperty", "hello");
     ----^
    ..
    }
    

    throws System.Web.Security.MembershipUser' does not contain a definition for 'SetProperty'

    Also tried:

    member.MemberProperties.Find(x => x.Alias == "customProperty").Value = "hello";
    

    without success, as it complains no such method MemberProperties.

    Any ideas on how to set a custom property of a member just created?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 05, 2016 @ 06:45
    Dave Woestenborghs
    0

    Hi Keilo,

    We use the MemberService to update/create our members.

    Here is some example code that works for us using the memberservice

    var service = ApplicationContext.Current.Services.MemberService;
                var member = service.GetById(memberId);
    
                if (member == null)
                {
                    return false;
                }
    
                member.SetValue("Adddress", "address string goes here");
    
                service.Save(member);
    

    You can find the memberservice docs here : https://our.umbraco.org/documentation/Reference/Management/Services/MemberService

    Dave

  • 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