Return values from HttpContext.Current.User.Principal and WindowsIdentity.GetCurrent()

Here is a brief explanation;

According to this forum on WindowsIdentity.GetCurrent().Name vs. User.Identity.Name:

  • User.Identity.Name represents the identity passed from IIS.
  • WindowsIdentity.GetCurrent().Name is the identity under which the thread is running.

Depending on your app’s authentication settings in IIS, they will return different values:

AnonymousImpersonateUser.Identity.NameWindowsIndentiy.GetCurrent()
YesTrueEmpty StringIUSR_<machineName>
YesFalseEmpty StringNT Authority\Network Service
NoTruedomain\userdomain\user
NoFalsedomain\userNT Authority\Network Service

Legend:

  • Where domain\user will show up as:
    • domain\user for Active Directory
    • machineName\userName for local account
  • Where NT Authority\Network Service will show up as:
    • NT Authority\Network Service for Windows Server or ASP.NET
    • machineName\ASPNET_WP for Windows XP

Resource

https://stackoverflow.com/questions/5402249/httpcontext-current-user-principal-vs-windowsidentity-getcurrent

FavoriteLoadingAdd to favorites
Spread the love

Author: Shahzad Khan

Software developer / Architect