Try our conversational search powered by Generative AI!

Passing information from Save to PublishedContent event

Vote:
 

Hi, I've created a IContentEvents.PublishedContent handler. In this handler I would like to know what code triggered the PublishContent event.

Is there any way to do this?

A code example

events.PublishedContent += EventsPublishedContent;

private void EventsPublishedContent(object sender, ContentEventArgs e)
 {
  //Here I would like to know who triggered me
}


DataFactory.Instance.Save(newPage, SaveAction.Publish, AccessLevel.NoAccess); // Here I would like to pass on information to PublishedContent 

I'm on EpiServer CMS 9.

#189364
Edited, Mar 16, 2018 9:44
Vote:
 

What exactly would you like to know.  Sender should give you who is ending the event but can you be more specific on what you mean by "Who triggered me".  are you looking for a class, another event, or scheduled job, etc.. 

#189399
Mar 17, 2018 17:41
Vote:
 

Hi Joshua,

I am looking for what class did the save action. The sender in the event is always of type {EPiServer.Core.DefaultContentEvents}, so unless there is a way to drill down in this object to get the original invoker, I don't see how the sender object helps.

I've also tried to set the ContentEventArgs.Creator property in the Publishing event, but this always cancel the save.

#189414
Mar 19, 2018 9:40
Vote:
 

Hi Steinar Skeie

The creator property is for creating new page not for updating any existing page.

One of the alternate would be kinda hack you can extend newsPage and add an object within it. Decorate that object with [ignore] so it does not apepar in editor section and pass the source in the newsPage where you are saving content.

Cheers

#189456
Mar 20, 2018 0:50
Vote:
 

Hi Murtaz, thanks for the answer, I've marked your reply as an answer to the problem. Hackish, but I guess EpiServer can't do any better.

#189596
Mar 21, 2018 9:23
Vote:
 

Steinar,
If you think that most developers would benefit from your suggestion, please add it to the feature requests forum: https://world.episerver.com/forum/developer-forum/Feature-requests/.

#189635
Mar 21, 2018 16:32
Vote:
 

The heading of this topic questions on how to pass information between content event handlers, that can be done using the property ContentEventArgs.Items which is a dictionary that you can use to pass data between event handlers.

Regarding the question on what code that triggered the event, you could use type SystemDiagnostics.StackTrace from .net to do so, like:

 var stackTrace = new StackTrace();           // get call stack
            var frames = stackTrace.GetFrames();  // get method calls (frames)

You should though be aware that GetFrames method is performance wise a quite expensive call.

#189701
Mar 23, 2018 8:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.