Copied to clipboard

Flag this post as spam?

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


  • Robert Mulder 79 posts 272 karma points c-trib
    Mar 07, 2014 @ 13:49
    Robert Mulder
    0

    Member.BeforeSave/AfterSave events do not fire

    After hooking up the BeforeSave or AfterSave events on the Member object like so:

    public class MemberEvents : ApplicationEventHandler {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
            base.ApplicationStarted(umbracoApplication, applicationContext);
    
            umbraco.cms.businesslogic.member.Member.AfterSave += Member_AfterSave;
        }
    
        void Member_AfterSave(umbraco.cms.businesslogic.member.Member sender, umbraco.cms.businesslogic.SaveEventArgs e) {
            // do something
        }
    }
    

    The AfterSave method only gets called when one of the (three) membership properties has changed. This means that when I add a custom field to the Member Type and change only that field, the Member object (including the custom field) does get saved, but no event is triggered.

    Looking around the Umbraco code I noticed that the FireAfterSave gets called from the Save() method, but in my use case the Save() method only gets called by the UpdateUser() method on the UmbracoMembershipProvider which in turn only gets called if the MemberController had determined that the MembershipUser has changed via the HasMembershipUserChanged() method.

    Unfortunatly my custom field is not part of the MembershipUser and thus does not trigger the event.

    Am I doing something wrong here or is there just a bug in Umbraco that prevents the BeforeSave/AfterSave method from fireing on changes of my custom property?

  • Chad 66 posts 130 karma points c-trib
    Mar 18, 2014 @ 02:49
    Chad
    101

    7.1 (currently in beta but scheduled for RC later this week) brings with it new API's for working with members. This will apparently fix a lot of issues with the legacy systems.

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        MemberService.Saving += MemberService_Saving;
    }
    
  • Robert Mulder 79 posts 272 karma points c-trib
    Mar 18, 2014 @ 09:10
    Robert Mulder
    0

    Thanks Chad, I'll look into it once we've upgraded to 7.1

    Is there any documentation on the new MemberService?

Please Sign in or register to post replies

Write your reply to:

Draft