Copied to clipboard

Flag this post as spam?

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

  • Matt Barlow ( 149 posts 658 karma points c-trib
    3 days ago
    Matt Barlow (

    Get userId of the user that saved content in the ContentService.Saving event.

    I have a tool that imports content and saves it with userId -1 (importer tool user). When importing with this tool, there should be no content validation.

    I also have a subscription to the ContentSaving event:

       ContentService.Saving += OnSaving;


      private void OnSaving(IContentService sender, ContentSavingEventArgs e)
            foreach (var node in e.SavedEntities)
                    if (node.WriterId != -1)
                        Validate(node, e);

    Which all works fine when importing, the WriterId is -1 and the validation doesn't occur, so the content is saved.

    Now when a I log in and and save that data (different userId), this event is hit again. I want the validation to occur. This time the expected behaviour is because the user isn't -1 then the Validate() function should be called.

    However I'm finding that the id is still -1 for the WriterId, so the Validate() function doesn't fire. This saves the user, then updates the WriterId to my userId, so when I save again this time the validation fires.

    Assuming this is because it's checking the current state and getting the writerId rather than getting the userId from user saving?

    So TLDR:

    How do I get the correct userId of the user performing the save action in the Content.Saving event?

  • Nik 1304 posts 5527 karma points MVP 3x c-trib
    3 days ago

    Have you tried getting the current back office user? Off the top of my head I can't be certain how you do that though.

Please Sign in or register to post replies

Write your reply to: