Request.ServerVariables ["LOGON_USER"]与Request.LogonUserIdentity

Sas*_*ach 7 .net c# asp.net authentication iis

我试图从ASP.Net应用程序的调用者那里获得当前的WindowsIdentity而不进行模拟.

阅读一些文章后我的设置是:

  • 在我的IIS中,我在身份验证设置中启用了Windows身份验证
  • 在我的web.conf中,我将身份验证模式设置为"Windows"

出于测试目的,我编写了以下日志语句

m_techLogger.Warn(string.Format("Request[LOGON_USER] {0}", Request["LOGON_USER"]));
m_techLogger.Warn(string.Format("Request.LogonUserIdentity {0}", Request.LogonUserIdentity.Name));
m_techLogger.Warn(string.Format("HttpContext.Current.User.Identity {0}", HttpContext.Current.User.Identity.Name));
m_techLogger.Warn(string.Format("WindowsIdentity.GetCurrent() {0}", WindowsIdentity.GetCurrent().Name));
Run Code Online (Sandbox Code Playgroud)

这些陈述返回以下内容

2015-04-23 10:47:19,628 [7] WARN  - Request[LOGON_USER] DOMAIN\User
2015-04-23 10:47:19,681 [7] WARN  - Request.LogonUserIdentity NT AUTHORITY\SYSTEM
2015-04-23 10:47:19,681 [7] WARN  - HttpContext.Current.User.Identity NT AUTHORITY\SYSTEM
2015-04-23 10:47:19,681 [7] WARN  - WindowsIdentity.GetCurrent() NT AUTHORITY\SYSTEM
Run Code Online (Sandbox Code Playgroud)

我了解WindowsIdentity.GetCurrent().Name返回系统用户.我不明白为什么Request.LogonUserIdentity和Request [LOGON_USER]的输出不同.我需要来自User的WindowsIdentity对象,其名称由Request [LOGON_USER]返回.

任何人都能指出我正确的方向吗?

rst*_*rst 2

当我尝试同样的事情时我得到

    Request.LogonUserIdentity.Name  "DOMAIN\\accountname"   (no capital letter)
    Request["LOGON_USER"]   "DOMAIN\\Accountname"   (capital letters)
Run Code Online (Sandbox Code Playgroud)

为了获取我们的 ASP.NET 应用程序中的当前用户,我使用了这行代码

User.Identity.Name
Run Code Online (Sandbox Code Playgroud)

这有什么帮助吗?