Monday, 2 June 2014

Programmatically add new member to a group in Umbraco 7

If you want to assign a new member to an Umbraco member group in .net, you have to use the "MemberService.AssignRole" method.


IMember _newMember = ApplicationContext.Current.Services.MemberService.CreateMember("username", "user@email.com", "Full Name", "Member");
Services.MemberService.Save(_newMember);
Services.MemberService.AssignRole(_newMember.Id, "Group Name");


The new member has to be saved first before you can assign it to role/group.