I trying to get the current WindowsIdentity from a caller of an ASP.Net Application without impersonation.
After reading some articles my setup is:
- In my IIS I have enabled the Windows Authentication in the Authentication Settings
- At my web.conf I set the authentication mode to "Windows"
For testing purposes, I wrote the following log statements
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));
This statements returned the following
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
I understand that WindowsIdentity.GetCurrent().Name returns the System User. I do not understand why the output from Request.LogonUserIdentity and Request[LOGON_USER] are different. I need the WindowsIdentity Object from the User with the name that returned by Request[LOGON_USER].
Can anybody point me in the right direction?