【问题标题】:Why do Thread.CurrentPrincipal.Identity and WindowsIdentity.GetCurrent() differ when impersonation is turned on?为什么打开模拟时 Thread.CurrentPrincipal.Identity 和 WindowsIdentity.GetCurrent() 不同?
【发布时间】:2013-08-14 20:30:44
【问题描述】:

我启用了模拟和 Windows 身份验证。

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

但是Thread.CurrentPrincipal.Identity.Name返回经过身份验证的用户名,WindowsIdentity.GetCurrent()返回模拟身份。

这些身份不应该一样吗?

在这种情况下,代码在哪些凭据下运行?

【问题讨论】:

    标签: asp.net security impersonation windows-identity current-principal


    【解决方案1】:

    据我所知,Thread.CurrentPrincipal 包含线程启动条件的信息,包括 WindowsIdentity。这就是Thread.CurrentPrincipal.Identity.Name 返回启动线程的用户名的原因。 相反 WindowsIdentity.GetCurrent() 返回一个代表当前 Windows 用户的 WindowsIdentity 对象,该用户已通过 Impersonation 进行了更改。 我不是 100% 确定它,但我认为它是这样工作的。

    【讨论】:

    • 完全按照您所说的工作。 Thread.CurrentPrincipal 被设置为身份验证的结果。无论是 Basic、Digest、Windows 还是 Forms 身份验证。这个原则无非是从用户那里收到一张票。和 WindowsIdentity 相关的运行线程和进程。如果只有 Windows 身份验证。已启用并启用模拟,则身份将相同。如果启用匿名登录,则 CurrentPrinciple.Identity 的名称为空。
    猜你喜欢
    • 1970-01-01
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 2022-09-26
    • 2017-09-10
    • 2018-06-04
    相关资源
    最近更新 更多