Copied to clipboard

Flag this post as spam?

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


  • Jeric Yuen 334 posts 508 karma points
    Jul 22, 2019 @ 16:55
    Jeric Yuen
    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

  • Jeric Yuen 334 posts 508 karma points
    Jul 23, 2019 @ 08:13
    Jeric Yuen
    0

    I'll try it out, thanks David

  • Jeric Yuen 334 posts 508 karma points
    Jul 23, 2019 @ 09:50
    Jeric Yuen
    1

    All good David

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies