Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Jul 22, 2019 @ 16:55
    Jay
    0

    ApplicationEvent MediaService.Saved getting user who trigger the event

    Hi All,

    Was wondering if there's a way I can get back the user who triggered the Save of a media from within the ApplicationEventHandler

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            MediaService.Saved += this.MediaService_Saved;
        }
    
        #endregion
    
        private void MediaService_Saved(IMediaService sender, SaveEventArgs<IMedia> e)
        {   // inside here to get back the user that trigger the save of the media event
        }
    

    thanks

  • David Challener 80 posts 444 karma points c-trib
    Jul 23, 2019 @ 07:54
    David Challener
    100

    Hi,

    Not sure if this is the "proper" way of doing it but I've used this before:

        using Umbraco.Web;
    
        private void MediaService_Saved(IMediaService sender, SaveEventArgs<IMedia> e)
        {
            // fetch the current User
            var currentUser = UmbracoContext.Current.Security.CurrentUser;
    
            foreach (var mediaItem in e.SavedEntities)
            {
                // each media saved.
            }
        }
    

    HTH, David

  • Jay 425 posts 652 karma points
    Jul 23, 2019 @ 08:13
    Jay
    0

    I'll try it out, thanks David

  • Jay 425 posts 652 karma points
    Jul 23, 2019 @ 09:50
    Jay
    1

    All good David

Please Sign in or register to post replies

Write your reply to:

Draft