启用模拟时,为什么Thread.CurrentPrincipal.Identity和WindowsIdentity.GetCurrent()不同? [英] Why do Thread.CurrentPrincipal.Identity and WindowsIdentity.GetCurrent() differ when impersonation is turned on?
问题描述
我启用了模拟和Windows身份验证.
I enabled impersonation and windows authentiaction.
<authentication mode="Windows" />
<identity impersonate="true" userName="name" password="passord"/>
但是Thread.CurrentPrincipal.Identity.Name
返回经过身份验证的用户的名称,而WindowsIdentity.GetCurrent()
返回模拟的身份.
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?
推荐答案
据我了解,Thread.CurrentPrincipal
包含线程已启动的条件的信息,包括WindowsIdentity.这就是为什么Thread.CurrentPrincipal.Identity.Name
返回启动线程的用户名称的原因.
相反,WindowsIdentity.GetCurrent()返回表示当前Windows用户的WindowsIdentity对象,该对象已通过模拟进行了更改.
我不是100%知道它,但这就是我认为的原理.
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.
这篇关于启用模拟时,为什么Thread.CurrentPrincipal.Identity和WindowsIdentity.GetCurrent()不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!