HttpContext.Current.User.Identity.Name is null

20,798

When I have:

<authentication mode="Windows"/>
<identity impersonate="true/>

in web.config I get the current user with:

string currUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
Share:
20,798
Nick
Author by

Nick

Updated on July 15, 2022

Comments

  • Nick
    Nick almost 2 years

    I'm trying to use HttpContext.Current.User.Identity.Name to get the user's Windows login details from the internal network, however it's empty.

    I've tried changing the authentication mode in Web.Config with no joy:

      <system.web>
        <authentication mode="Windows" />
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
      </system.web>
    

    I've also heard that in the project properties you should enable Windows authentication and disable anonymous authentication like so:

    enter image description here

    But then I get a re-direct loop, with the message "This webpage has a redirect loop" in Chrome.

    I've also checked that Windows Authentication is installed on my machine:

    enter image description here

    Any ideas on how to fix this please?

    Many thanks

  • Nick
    Nick almost 10 years
    Thank you very much for the reply, however I get the following error: An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. Most likely causes: system.web/identity@impersonate is set to true.
  • Nick
    Nick almost 10 years
    Further to the above, I got rid of the error: stackoverflow.com/questions/4209999/… However unfortunately the value System.Security.Principal.WindowsIdentity.GetCurrent().Name of is still null :(