【问题标题】:HttpContext.Current.User.Principal vs WindowsIdentity.GetCurrent()HttpContext.Current.User.Principal 与 WindowsIdentity.GetCurrent()
【发布时间】:2011-03-23 07:54:02
【问题描述】:

在启用了 Windows 身份验证和身份模拟的 asp.NET 环境中,HttpContext.Current.User.Principal 和 WindowsIdentity.GetCurrent() 有什么区别?

【问题讨论】:

  • 虽然这个问题已经回答过了,但是我发现thisthis link回答得比较清楚。

标签: asp.net iis windows-authentication


【解决方案1】:

据此论坛WindowsIdentity.GetCurrent().Name vs. User.Identity.Name

  • User.Identity.Name 表示从 IIS 传递的标识。
  • WindowsIdentity.GetCurrent().Name 是线程运行的标识。

根据您应用在 IIS 中的身份验证设置,它们将返回不同的值:

| @987654322@ | @987654323@ | User.Identity.Name | WindowsIndentiy.GetCurrent()  |
|-----------|-------------|--------------------|-------------------------------|
| Yes       | True        | Empty String       | IUSR_<machineName>            |
| Yes       | False       | Empty String       | NT Authority\Network Service  |
| No        | True        | domain\user        | domain\user                   |
| No        | False       | domain\user        | NT Authority\Network Service  |

传奇

  • domain\user 将显示为:
    • Active Directory 的域\用户
    • 本地帐户的机器名\用户名
  • NT Authority\Network Service 将显示为:
    • NT Authority\Network Service for Windows Server 或 ASP.NET
    • machineName\ASPNET_WP for Windows XP

【讨论】:

    猜你喜欢
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 2019-01-02
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    相关资源
    最近更新 更多