Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpContext.Current.User.Identity.Name is null

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

like image 412
Nick Avatar asked Mar 18 '23 21:03

Nick


1 Answers

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();
like image 176
Martin Smellworse Avatar answered Mar 27 '23 13:03

Martin Smellworse