Question

I'm trying to get user's windows login from the server and all methods that I tried are returning the network's details.

I did put <identity impersonate="true"> in my web.config but no help.

here's my webconfig:

<?xml version="1.0"?>
<configuration>
<appSettings>
 <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<authentication mode="Windows"/>
<identity impersonate="true"/>
<compilation targetFramework="4.5" debug="true"/>
<httpRuntime targetFramework="4.5"/>
<sessionState timeout="20"/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>

and here's my C# call:

string id1 = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string id2 = Page.User.Identity.Name;
string id3 = Request.LogonUserIdentity.Name;

ALL 3 RETURNS EMPTY OR WITH NETWORK DETAILS. any solution??

Was it helpful?

Solution

If your entire web site requires Windows authentication, you should make sure that Anonymous Authentication is disabled. To do so:

  1. Open the Internet Information Services (IIS) Manager.
  2. Select your web application and open the Authentication feature.
  3. Make sure "Anonymous Authentication" is disabled and "Windows Authentication" is enabled.

Once anonymous authentication is disabled, your code for id2 or id3 will have the Windows logon information. Your id1 code will report the identity of the application pool.

If only part of your web site requires authentication and other parts do not, then your web.config should define authorization rules (and Anonymous Authentication should remain enabled). For example, you can deny access by anonymous users to all pages by default but specifically allow anonymous access to Default.aspx.

<configuration>

  <system.web>
    ...
    <authorization>
      <deny users="?"/>
    </authorization>
     ...
 </system.web>

  <location path="Default.aspx">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

</configuration>

Windows authentication does not require your application to implement a login process. It will issue the authentication challenge to the browser. Some browsers like IE will supply the Windows credentials automatically and others like Firefox will present a login prompt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top