3

I'm trying to impersonate a user in a C# TBB. is it possible to know who initiated the publish action of a component in the TBB which is a part of the component template rendering with the component?

Rohan Gadiya
  • 338
  • 1
  • 6

2 Answers2

9

As mentioned in below article

http://yatb.mitza.net/2012/05/publishing-from-template-code-using.html

Once you will get the Current Publish transaction you can use the properties .Creator to get the user.

To get the Current Publish Transaction you can refer

http://yatb.mitza.net/2012/05/publishing-from-template-code-using.html

Mihai Cădariu
  • 2,407
  • 14
  • 17
Ram Saurabh
  • 1,586
  • 8
  • 27
  • I was not able to get the current user by using : engine.PublishingContext.RenderContext.ContextItem.Session.User which I thought I would. The links provided had the solution. Many Thanks Ram. – Rohan Gadiya Oct 04 '12 at 21:29
6

In your TBB you have access to the engine.GetSession(), which returns a Session object, containing the User information, I'm sure via that you can do in your code, what you are trying to achieve.

It would be interesting to know a little more about what you are trying to archive.

johnwinter
  • 3,624
  • 15
  • 24
  • First of all thank you for the info John. It worked! I want to push a few items to the publishing Q using the same user id which published the component which is getting rendered with the CT. So when some items are pushed to the Q automatically through code we know which user triggered it. – Rohan Gadiya Oct 03 '12 at 23:15
  • The engine.GetSession() contains a User for whom the Session was created. In your case (in templating), it's most likely the SYSTEM user. As I understand, Ram wants the user who 'initiated the publish'... and that's not SYSTEM. – Mihai Cădariu Oct 10 '12 at 14:55