locked
WindowsIdentity.GetCurrent().Name versus HttpContext.Current.User.Identity.Name w/Windows Authentication RRS feed

  • Question

  • User-1863801078 posted

    I have set up an admin site in our intranet using Active Directory. On my test box, WindowsIdentity.GetCurrent().Name but on my new prod box HttpContext.Current.User.Identity.Name w/Windows Authentication seems to work. When I compare the IIS settings XML for each box they seem to be the same.

    Can anyone tell me what decides which one is correct? Then, maybe, I can made them the same.

    Wednesday, April 9, 2014 1:40 PM

Answers

  • User1779161005 posted

    WindowsIdentity.GetCurrent() gets the hosting process identity.

    HttpContext.Current.User.Identity gets the authenticated user making the HTTP request. This is the one you want (most likley).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 9, 2014 1:46 PM

All replies

  • User1779161005 posted

    WindowsIdentity.GetCurrent() gets the hosting process identity.

    HttpContext.Current.User.Identity gets the authenticated user making the HTTP request. This is the one you want (most likley).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 9, 2014 1:46 PM
  • User753101303 posted

    Hi,

    User.Identity.Name is preferred when you want to know which identity is used to log to the site (it works even if using form authentication or whatever).

    Something such as WindowsIdentity.GetCurrent is rather the account under which the code runs and it is not necessarily the same thing than the account used to log to the site (though it is on a dev box as the code typically runs in IIS Express under your own account).

    Wednesday, April 9, 2014 1:53 PM