4

On the client I have setup the bus with ImpersonateSender(true)

My server is configured AsA_Server, which by default should have ImpersonateSender(true)

I'm now trying to retrieve the WindowsIdentity, from inside a Handler

var windowsIdentity = WindowsIdentity.GetCurrent(true);

But this is giving me null.

What am I doing wrong?

John Simons
  • 4,288
  • 23
  • 41

1 Answers1

6

Use System.Threading.Thread.CurrentPrincipal instead.

Also, don't set ImpersonateSender on the client - it'll send it's credentials regardless.

Udi Dahan
  • 11,932
  • 1
  • 27
  • 35
  • I looked at that, but that only gives me a GenericPrincipal. I need to get WindowsIdentity so I can get the windows token for the user. – John Simons May 17 '10 at 11:45
  • Tackling the problem in a different way: http://stackoverflow.com/questions/2854198/nservicebus-how-to-pass-custom-headers-in-the-message-envelop – John Simons May 18 '10 at 21:47
  • 1
    Inside the CurrentPrincipal is an IIdentity which can be cast to a WindowsIdentity. – Udi Dahan Jun 02 '10 at 14:52
  • Hi I have one question here. How to execute the stored message on certain windowsIdentity. Is there any way to recreate the windowsidentity.currentprincipal from incoming message header ? Because when I crash Saga and re-run then the incoming messages are getting executed in my windows credential. Which is wrong , it was supposed to run on the original context which – Rupesh Kumar Tiwari Jun 09 '15 at 17:47
  • I tried even from MVC webproject i am getting windows identity correct. However when it goes to End point then Thread.CurrentPrincipal is different it takes from my windowsNT id. NSErvicebus is not passing the exact CurrentPrincipal which is there in MVC web project. Request.LogonUserIdentity . Is there anyway to pass exact logonUserIdentity to Endpoint ? – Rupesh Kumar Tiwari Jun 09 '15 at 19:05
  • I have another thread for my issue related to this http://stackoverflow.com/questions/30736912/how-to-impersonate-nservicebus – Rupesh Kumar Tiwari Jun 10 '15 at 17:28