How to identify who the client is, in an intranet environment

Coreysan 1,436 Reputation points

I realize browser identity is very secure, but I wanted to know if the following can be done:

I have a C# ASP.NET app running on company intranet server.

Right now, in Code behind I can use IPHostEntry to get the client machine name, so that's good. Once I know the machine name, can I get the Windows username?

A set of technologies in the .NET Framework for building web applications and XML web services.
1,716 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 19,681 Reputation points Microsoft Vendor

    Hi @Coreysan,

    Once I know the machine name, can I get the Windows username?

    There is no necessary connection between the two.

    You can try using

    Environment.UserName (If you test Environment.UserName using RunAs, it will give you the RunAs user account name, not the user originally logged on to Windows.)


    String UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name (returns DomainName\UserName);


    set authentication mode to Windows in your configuration & also disable anonymous users in authorization tag.

            <authentication mode="Windows" />
                 <deny users="?"/>

    var userId = this.User.Identity.Name;

    Enabling Windows Authentication within an Intranet ASP.NET Web application

    Best regards,
    Lan Huang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

1 additional answer

Sort by: Most helpful
  1. SurferOnWww 1,296 Reputation points

    Please consider use of the Windows Authentication.

    Windows Authentication

    To my knowledge, there is no way to get the Windows username from the HostName and other information obtained from the properties of IPHostEntry.

    You will be able to use the ASP.NET Identity or ASP.NET Forms Authentication instead of the Windows Authentication to get the username provided that a user registers his Windows username as the id of such authentication system.