Why do Thread.CurrentPrincipal.Identity and WindowsIdentity.GetCurrent() differ when impersonation is turned on?

自闭症网瘾萝莉.ら 提交于 2019-12-09 00:01:24

问题


I enabled impersonation and windows authentiaction.

<authentication mode="Windows" />
<identity impersonate="true" userName="name" password="passord"/>

But Thread.CurrentPrincipal.Identity.Name returnes the name of authenticated user and WindowsIdentity.GetCurrent() returns impersonated identity.

Shouldn't these identities be the same?

And under wich credentials does the code run in this case?


回答1:


As far as I can understand the Thread.CurrentPrincipal contains the information of conditions the thread has been started with, including the WindowsIdentity. That's why Thread.CurrentPrincipal.Identity.Name returns the name of User who started the thread. To the contrary WindowsIdentity.GetCurrent() Returns a WindowsIdentity object that represents the current Windows user, which has been changed via Impersonation. I'm not 100% sure about it, but that's how I think it works.



来源:https://stackoverflow.com/questions/18205458/why-do-thread-currentprincipal-identity-and-windowsidentity-getcurrent-differ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!