Copied to clipboard

Flag this post as spam?

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


  • Miguel Lopez 15 posts 117 karma points
    Jul 10, 2018 @ 09:11
    Miguel Lopez
    0

    Inconsistent user key on SavedUser event

    When using the UserService.SavedUser event, the saved entities return inconsistent keys. If I am editing the user properties, it returns what seems a legit key (671F56D6-5417-46C1-B6EF-17057E0F92F5). If I am enabling or disabling a user, then it returns a totally different key (00000003-0000-0000-0000-000000000000) which seems to be related to the user Id (3).

    I hooked to the SavedUser event, and added a custom method to perform operations on saved.

    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
         UserService.SavedUser += CustomUserEventHandler.UserServiceSaved;
         UserService.DeletedUser += CustomUserEventHandler.UserServiceDeleted;
    }
    
    private static void UserServiceSaved(IUserService sender, SaveEventArgs<IUser> e)
    {
         foreach (var user in e.SavedEntities)
         {
              var userKey = user.Key;
         }
    }
    

    I need to store the key in a custom table where I store a custom entity referencing the user.

    By using the method above, when I create the user, I add a row to my custom table with the user key. Later, when I edit, enable or disable the user, I perform a Get from my custom table by member key.

    When I edit the user, the saved entity has the key 671F56D6-5417-46C1-B6EF-17057E0F92F5. When I enable/disable, the entity has the key 00000003-0000-0000-0000-000000000000, so it makes it impossible to get from my custom table.

    I kind of understand why enabling/disabling would return different keys, but is there a way or shouldn't there be a way to know the actual key of the user it is referencing?

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft