【发布时间】:2015-07-01 22:35:00
【问题描述】:
我试图从 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));
此语句返回以下内容
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
我了解 WindowsIdentity.GetCurrent().Name 返回系统用户。我不明白为什么 Request.LogonUserIdentity 和 Request[LOGON_USER] 的输出不同。我需要来自用户的 WindowsIdentity 对象,其名称由 Request[LOGON_USER] 返回。
谁能指出我正确的方向?
【问题讨论】:
-
你的代码是
Request["LOGON_USER"]。不应该是Request.ServerVariables[“LOGON_USER”]吗? -
您似乎没有启用模拟。详情请见MSDN。
标签: c# asp.net .net authentication iis