U4-6278 - Member groups/roles not updated correctly in MemberService.Saving and MemberService.Saved handlers

Created by Joseph 15 Feb 2015, 22:19:25 Updated by Paul 22 Feb 2017, 12:44:44


I'm looking at working with Umbraco's membership system such that when a member is moved into and out of specific groups/roles (the two seem to be used interchangeably on forums, documentation and the CMS UI), I do stuff (which is not particularly relevant to the issue at hand).

Here's the code that I have been working with:

protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { MemberService.Saved += DoStuffWithSavedMember; }

    private void DoStuffWithSavedMember(IMemberService sender, SaveEventArgs<IMember> saveEventArgs)
        var savedMember = saveEventArgs.SavedEntities.FirstOrDefault();
        if (savedMember != null)
            var roles = sender.GetAllRoles(savedMember.Username).ToList();

            if (!roles.Any() || (roles.Count == 1 && roles.Single() == "Base User"))
                //do something
                //do something else

The problem that I am having is that sender.GetAllRoles seems to be one step behind i.e. when I add a member to a group/role and save; sender.GetAllRoles only registers the new group/role the second time i.e. if I hit save twice. I've not had the opportunity to delve into Umbraco source but it looks like sender.GetAllRoles is still stuck at a state before the save is invoked and so is always one step behind.

Assuming this is a reproducible bug; could you also please suggest how I can work around this issue? I'm hoping there is an older/deprecated API call that I can make in the meantime...

2 Attachments


Jeremy Paden 17 Apr 2015, 17:15:30

I have noticed this issue as well. MemberService.Saved is raised as a result of a call to Services.MemberService.Save in Umbraco.Web.MemberController.PostSave. After the call to Services.MemberService.Save, the PostSave method overwrites the roles of the member using the roll collection on contentItem. Therefore any changes made to roles within MemberService.Saving or MemberService.Saved handlers will be overwritten. See the attached screen shot for details. Is there a suggested workaround for this?

My use case is that I have custom properties for email communication preferences. When a user modifies their communication preferences, the member is added to the appropriate membership roles. This used to work fine in previous versions of Umbraco. What is the best way to modify Roles based on member property values now?

Edit - This works fine when updating the member through code directly, but is an issue when saving a member through the backoffice. I noticed this issue when switching from using the obsolete umbraco.cms.businesslogic.member.Member.AfterSave handler to the new MemberService.Saved handler.

Jeremy Paden 29 Jun 2015, 16:27:30

Is there any update on this defect? I have been unable to find a suitable workaround for this. This issue is causing a significant problem for my client because they are unable to effectively manage their members.

Paul 22 Feb 2017, 12:44:44

Try... var IsInRole = System.Web.Security.Roles.IsUserInRole("memberGroup");

Priority: Critical

Type: Bug

State: Submitted


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 7.2.1

Due in version:


Story Points: