Search code examples
asp.netasp.net-mvcumbracoumbraco7

Extend umbraco member with property


I am developing web site on umbraco and need to store additional information about member(cmsMember). How can I do that? Is there a way to extend umbraco member without changing membership provider?

I would like to do something similar to this

  var datatype = new DataTypeDefinition("varchar");
  var type = new PropertyType(datatype);
  var property = new Property(type);
  property.Value = myAdditionalInfo;
  member.Properties.Add(property);
  memberService.Save(member, false);

Code above right now throws exception with Value cannot be null message.


Solution

  • Adding properties to a Member type can (and should) be done in the backoffice:

    Member Type Properties

    And then setting/saving the values should be something like this (using MemberService), though I'm not exactly sure if it's current :-s :

    // Get the member
    var member = Member.GetCurrentMember();
    
    // Check if there is a current member
    if (member != null)
    {
        // Update member properties
        member.getProperty("myPropertyAlias").Value = myAdditionalInfo;
    
        // Save the updated member
        member.Save(); 
    }